Do not trigger callbacks if a object got refreshed and is still the same.

This commit is contained in:
Martin Edenhofer 2014-08-14 16:45:33 +02:00
parent 2c74ea2f61
commit 611161c76c

View file

@ -291,7 +291,7 @@ class App.Model extends Spine.Model
# subscribe and render data after local change # subscribe and render data after local change
@bind( @bind(
'refresh change' 'change'
(items) => (items) =>
# check if result is array or singel item # check if result is array or singel item
@ -301,7 +301,26 @@ class App.Model extends Spine.Model
for item in items for item in items
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ] for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
item = App[ @className ]._fillUp( item ) item = App[ @className ]._fillUp( item )
callback(item) callback(item, 'change')
)
@changeTable = {}
@bind(
'refresh'
(items) =>
# check if result is array or singel item
if !_.isArray(items)
items = [items]
for item in items
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
# only trigger callbacks if object has changed
if !@changeTable[key] || @changeTable[key] isnt item.updated_at
@changeTable[key] = item.updated_at
item = App[ @className ]._fillUp( item )
callback(item, 'refresh')
) )
# subscribe and render data after server change # subscribe and render data after server change