Properly deregister polling hook when there's no models to poll

This commit is contained in:
Piotr Sarnacki 2015-05-11 14:53:58 +02:00
parent f9fcd3888c
commit 5c24778394
2 changed files with 21 additions and 8 deletions

View File

@ -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)

View File

@ -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()