Properly deregister polling hook when there's no models to poll
This commit is contained in:
parent
f9fcd3888c
commit
5c24778394
|
@ -48,15 +48,13 @@ mixin = Ember.Mixin.create
|
|||
@get('polling').startPollingHook(this) if @pollHook
|
||||
|
||||
stopPolling: ->
|
||||
pollModels = @get('pollModels')
|
||||
return unless pollModels
|
||||
if pollModels = @get('pollModels')
|
||||
pollModels = [pollModels] unless Ember.isArray(pollModels)
|
||||
|
||||
pollModels = [pollModels] unless Ember.isArray(pollModels)
|
||||
|
||||
pollModels.forEach (property) =>
|
||||
@stopPollingModel(property)
|
||||
@removeObserver(property, this, 'pollModelDidChange')
|
||||
Ember.removeBeforeObserver(this, property, this, 'pollModelWillChange')
|
||||
pollModels.forEach (property) =>
|
||||
@stopPollingModel(property)
|
||||
@removeObserver(property, this, 'pollModelDidChange')
|
||||
Ember.removeBeforeObserver(this, property, this, 'pollModelWillChange')
|
||||
|
||||
@get('polling').stopPollingHook(this)
|
||||
|
||||
|
|
|
@ -47,6 +47,21 @@ moduleForComponent 'polling-test', 'PollingTestComponent', {
|
|||
pollingChangesHistory = []
|
||||
}
|
||||
|
||||
test 'it properly stops polling hook without any models', ->
|
||||
component = @subject(pollModels: null)
|
||||
@append()
|
||||
|
||||
Ember.run ->
|
||||
component.destroy()
|
||||
|
||||
expected = [
|
||||
{ type: 'start-hook', source: '<PollingTestingComponent>' },
|
||||
{ type: 'stop-hook', source: '<PollingTestingComponent>' }
|
||||
]
|
||||
|
||||
deepEqual pollingChangesHistory, expected
|
||||
|
||||
|
||||
test 'it works even if one of the model is null', ->
|
||||
component = @subject(model1: { name: 'model1' })
|
||||
@append()
|
||||
|
|
Loading…
Reference in New Issue
Block a user