Fixed race condition in case of reloading whole collections.

This commit is contained in:
Martin Edenhofer 2014-02-11 02:56:32 +01:00
parent 8d4f4c0c25
commit 27b6de5ac1

View file

@ -130,9 +130,7 @@ class App.Model extends Spine.Model
for record in records for record in records
if @RETRIEVE_CALLBACK[ record.id ] if @RETRIEVE_CALLBACK[ record.id ]
for key, callback of @RETRIEVE_CALLBACK[ record.id ] for key, callback of @RETRIEVE_CALLBACK[ record.id ]
data = App[ @className ].find( record.id ) data = callback( @_fillUp( App[ @className ].find( record.id ) ) )
data = @_fillUp( data )
callback( data )
delete @RETRIEVE_CALLBACK[ record.id ][ key ] delete @RETRIEVE_CALLBACK[ record.id ][ key ]
if _.isEmpty @RETRIEVE_CALLBACK[ record.id ] if _.isEmpty @RETRIEVE_CALLBACK[ record.id ]
delete @RETRIEVE_CALLBACK[ record.id ] delete @RETRIEVE_CALLBACK[ record.id ]
@ -153,9 +151,9 @@ class App.Model extends Spine.Model
# subscribe and render data / fetch new data if triggered # subscribe and render data / fetch new data if triggered
@bind( @bind(
'refresh change' 'refresh change'
=> (items) =>
for key, callback of @SUBSCRIPTION_COLLECTION for key, callback of @SUBSCRIPTION_COLLECTION
callback() callback(items)
) )
# trigger deleteAll() and fetch() on network notify # trigger deleteAll() and fetch() on network notify
@ -163,8 +161,7 @@ class App.Model extends Spine.Model
App.Event.bind( App.Event.bind(
events events
=> =>
@deleteAll() @fetch( {}, { clear: true } )
@fetch()
'Collection::Subscribe::' + @className 'Collection::Subscribe::' + @className
) )
@ -176,7 +173,7 @@ class App.Model extends Spine.Model
if param['initFetch'] is true if param['initFetch'] is true
@one 'refresh', (collection) => @one 'refresh', (collection) =>
callback(collection) callback(collection)
@fetch() @fetch( {}, { clear: true } )
return key return key