Only execute collection lookup via App.Model.subscribe min. callback exists.
This commit is contained in:
parent
f673c7028a
commit
8612c1a019
1 changed files with 23 additions and 22 deletions
|
@ -233,7 +233,7 @@ class App.Model extends Spine.Model
|
||||||
# subscribe and reload data / fetch new data if triggered
|
# subscribe and reload data / fetch new data if triggered
|
||||||
subscribeId = undefined
|
subscribeId = undefined
|
||||||
if bind
|
if bind
|
||||||
subscribeId = App[ @className ].subscribe_item(id, callback)
|
subscribeId = App[ @className ].subscribeItem(id, callback)
|
||||||
|
|
||||||
# execute if object already exists
|
# execute if object already exists
|
||||||
if !force && App[ @className ].exists(id)
|
if !force && App[ @className ].exists(id)
|
||||||
|
@ -345,6 +345,7 @@ class App.Model extends Spine.Model
|
||||||
App.Event.bind(
|
App.Event.bind(
|
||||||
events
|
events
|
||||||
=>
|
=>
|
||||||
|
return if _.isEmpty(@SUBSCRIPTION_COLLECTION)
|
||||||
App.Log.debug('Model', "server notify collection change #{@className}")
|
App.Log.debug('Model', "server notify collection change #{@className}")
|
||||||
@fetchFull(
|
@fetchFull(
|
||||||
->
|
->
|
||||||
|
@ -394,13 +395,13 @@ class App.Model extends Spine.Model
|
||||||
subscribe: (callback, type) ->
|
subscribe: (callback, type) ->
|
||||||
|
|
||||||
# remember record id and callback
|
# remember record id and callback
|
||||||
App[ @constructor.className ].subscribe_item(@id, callback)
|
App[ @constructor.className ].subscribeItem(@id, callback)
|
||||||
|
|
||||||
@subscribe_item: (id, callback) ->
|
@subscribeItem: (id, callback) ->
|
||||||
|
|
||||||
# init bind
|
# init bind
|
||||||
if !@_subscribe_item_bindDone
|
if !@_subscribeItemBindDone
|
||||||
@_subscribe_item_bindDone = true
|
@_subscribeItemBindDone = true
|
||||||
|
|
||||||
# subscribe and render data after local change
|
# subscribe and render data after local change
|
||||||
@bind(
|
@bind(
|
||||||
|
@ -454,16 +455,16 @@ class App.Model extends Spine.Model
|
||||||
App.Event.bind(
|
App.Event.bind(
|
||||||
events
|
events
|
||||||
(item) =>
|
(item) =>
|
||||||
if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ]
|
return if !@SUBSCRIPTION_ITEM || !@SUBSCRIPTION_ITEM[ item.id ]
|
||||||
App.Log.debug('Model', "server change on #{@className}.find(#{item.id}) #{item.updated_at}")
|
App.Log.debug('Model', "server change on #{@className}.find(#{item.id}) #{item.updated_at}")
|
||||||
callback = =>
|
callback = =>
|
||||||
genericObject = undefined
|
genericObject = undefined
|
||||||
if App[ @className ].exists(item.id)
|
if App[ @className ].exists(item.id)
|
||||||
genericObject = App[ @className ].find(item.id)
|
genericObject = App[ @className ].find(item.id)
|
||||||
if !genericObject || new Date(item.updated_at) > new Date(genericObject.updated_at)
|
if !genericObject || new Date(item.updated_at) > new Date(genericObject.updated_at)
|
||||||
App.Log.debug('Model', "request #{@className}.find(#{item.id}) from server")
|
App.Log.debug('Model', "request #{@className}.find(#{item.id}) from server")
|
||||||
@full(item.id, false, true)
|
@full(item.id, false, true)
|
||||||
App.Delay.set(callback, 600, item.id, "full-#{@className}-#{item.id}")
|
App.Delay.set(callback, 600, item.id, "full-#{@className}-#{item.id}")
|
||||||
"Item::Subscribe::#{@className}"
|
"Item::Subscribe::#{@className}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -471,13 +472,13 @@ class App.Model extends Spine.Model
|
||||||
App.Event.bind(
|
App.Event.bind(
|
||||||
events
|
events
|
||||||
(item) =>
|
(item) =>
|
||||||
if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ]
|
return if !@SUBSCRIPTION_ITEM || !@SUBSCRIPTION_ITEM[ item.id ]
|
||||||
return if !App[ @className ].exists(item.id)
|
return if !App[ @className ].exists(item.id)
|
||||||
genericObject = App[ @className ].find(item.id)
|
genericObject = App[ @className ].find(item.id)
|
||||||
App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}")
|
App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}")
|
||||||
callback = ->
|
callback = ->
|
||||||
genericObject.trigger('destroy', genericObject)
|
genericObject.trigger('destroy', genericObject)
|
||||||
App.Delay.set(callback, 500, item.id, "delete-#{@className}-#{item.id}")
|
App.Delay.set(callback, 500, item.id, "delete-#{@className}-#{item.id}")
|
||||||
"Item::SubscribeDelete::#{@className}"
|
"Item::SubscribeDelete::#{@className}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue