Fixed race condition of forced model.retrieve(). Added trigger for local model changes vi model.subscribe().
This commit is contained in:
parent
47841fbbac
commit
b4cd8db227
1 changed files with 15 additions and 1 deletions
|
@ -136,10 +136,13 @@ class App.Model extends Spine.Model
|
||||||
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 ]
|
||||||
|
@fetchActive = false
|
||||||
|
|
||||||
# fetch object
|
# fetch object
|
||||||
console.log 'debug', 'loading..' + @className + '..', id
|
console.log 'debug', 'loading..' + @className + '..', id
|
||||||
App[ @className ].fetch( id: id )
|
if !@fetchActive
|
||||||
|
@fetchActive = true
|
||||||
|
App[ @className ].fetch( id: id )
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
@ -183,11 +186,22 @@ class App.Model extends Spine.Model
|
||||||
if !App[ @constructor.className ]['SUBSCRIPTION_ITEM']
|
if !App[ @constructor.className ]['SUBSCRIPTION_ITEM']
|
||||||
App[ @constructor.className ]['SUBSCRIPTION_ITEM'] = {}
|
App[ @constructor.className ]['SUBSCRIPTION_ITEM'] = {}
|
||||||
|
|
||||||
|
# subscribe and render data after local change
|
||||||
|
@bind(
|
||||||
|
'refresh change'
|
||||||
|
=>
|
||||||
|
for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ]
|
||||||
|
callback(@)
|
||||||
|
)
|
||||||
|
|
||||||
|
# subscribe and render data after server change
|
||||||
events = "#{@constructor.className}:created #{@constructor.className}:updated #{@constructor.className}:destroy"
|
events = "#{@constructor.className}:created #{@constructor.className}:updated #{@constructor.className}:destroy"
|
||||||
App.Event.bind(
|
App.Event.bind(
|
||||||
events
|
events
|
||||||
(record) =>
|
(record) =>
|
||||||
if @id.toString() is record.id.toString()
|
if @id.toString() is record.id.toString()
|
||||||
|
|
||||||
|
# load only once from server
|
||||||
for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ]
|
for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ]
|
||||||
App[ @constructor.className ].retrieve( @id, callback, true )
|
App[ @constructor.className ].retrieve( @id, callback, true )
|
||||||
'Item::Subscribe::' + @constructor.className
|
'Item::Subscribe::' + @constructor.className
|
||||||
|
|
Loading…
Reference in a new issue