Fixed subscribe().
This commit is contained in:
parent
983dc703e4
commit
99b7c406f9
1 changed files with 13 additions and 7 deletions
|
@ -175,7 +175,8 @@ class App.Model extends Spine.Model
|
||||||
callback(collection)
|
callback(collection)
|
||||||
@fetch( {}, { clear: true } )
|
@fetch( {}, { clear: true } )
|
||||||
|
|
||||||
return key
|
# return key
|
||||||
|
key
|
||||||
|
|
||||||
subscribe: (callback) ->
|
subscribe: (callback) ->
|
||||||
|
|
||||||
|
@ -187,19 +188,22 @@ class App.Model extends Spine.Model
|
||||||
App[ @constructor.className ].bind(
|
App[ @constructor.className ].bind(
|
||||||
'refresh change'
|
'refresh change'
|
||||||
(item) =>
|
(item) =>
|
||||||
|
console.log('BIND', item)
|
||||||
for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ item.id ]
|
for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ item.id ]
|
||||||
item = App[ @constructor.className ]._fillUp( item )
|
item = App[ @constructor.className ]._fillUp( item )
|
||||||
callback(item)
|
callback(item)
|
||||||
)
|
)
|
||||||
|
|
||||||
# subscribe and render data after server change
|
# subscribe and render data after server change
|
||||||
events = "#{@constructor.className}:created #{@constructor.className}:updated #{@constructor.className}:destroy"
|
events = "#{@constructor.className}:create #{@constructor.className}:update #{@constructor.className}:destroy"
|
||||||
App.Event.bind(
|
App.Event.bind(
|
||||||
events
|
events
|
||||||
(record) =>
|
(item) =>
|
||||||
if @id.toString() is record.id.toString()
|
console.log('SERVER BIND try', item)
|
||||||
for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ]
|
if App[ @constructor.className ]['SUBSCRIPTION_ITEM'] && App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ item.id ]
|
||||||
App[ @constructor.className ].retrieve( @id, callback, true )
|
console.log('SERVER BIND', item)
|
||||||
|
for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ item.id ]
|
||||||
|
App[ @constructor.className ].retrieve( item.id, callback, true )
|
||||||
'Item::Subscribe::' + @constructor.className
|
'Item::Subscribe::' + @constructor.className
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -208,7 +212,9 @@ class App.Model extends Spine.Model
|
||||||
App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ] = {}
|
App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ] = {}
|
||||||
key = @constructor.className + '-' + Math.floor( Math.random() * 99999 )
|
key = @constructor.className + '-' + Math.floor( Math.random() * 99999 )
|
||||||
App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ][key] = callback
|
App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ][key] = callback
|
||||||
return key
|
|
||||||
|
# return key
|
||||||
|
key
|
||||||
|
|
||||||
@unsubscribe: (data) ->
|
@unsubscribe: (data) ->
|
||||||
if @SUBSCRIPTION_ITEM
|
if @SUBSCRIPTION_ITEM
|
||||||
|
|
Loading…
Reference in a new issue