ember-model
ember-model copied to clipboard
Calling reload multiple times doesn't wait for last call to finish loading
trafficstars
The reload method for recordArrays doesn't take into account the scenario where reload is called multiple times before the server returns.
Currently in this case, isLoaded is set to true on the first returning reload call, and the data from the last returning call will end up as the final data.
Expected behaviour:
isLoaded should only be set to true when the last initiated promise resolves, and data from that promise should be the data that is used.
Currently using the following code as a hacky workaround (which should help explain what is happening:
# Update reload method in Em.RecordArray to deal with multiple reload calls
Em.RecordArray.reopen
notifyLoaded: ->
reloadCount = @get 'reloading'
if typeof reloadCount == 'number'
@set 'reloading', --reloadCount
if reloadCount <= 0
@set 'reloading', 0
@_super()
else
@_super()
reload: ->
reloadCount = @get('reloading') + 1 || 1
@set 'reloading', reloadCount
@_super()
Could you please submit a PR with tests?