Improved client update, store in local storage also.
This commit is contained in:
parent
579ba37b2b
commit
e6c4aa5120
1 changed files with 14 additions and 6 deletions
|
@ -130,6 +130,7 @@ class _Singleton extends Spine.Module
|
||||||
|
|
||||||
# load full array once
|
# load full array once
|
||||||
if _.isArray( params.data )
|
if _.isArray( params.data )
|
||||||
|
if !params.refresh
|
||||||
App[ params.type ].refresh( params.data )
|
App[ params.type ].refresh( params.data )
|
||||||
|
|
||||||
# remember in store if not already requested from local storage
|
# remember in store if not already requested from local storage
|
||||||
|
@ -141,6 +142,7 @@ class _Singleton extends Spine.Module
|
||||||
# load data from object
|
# load data from object
|
||||||
# if _.isObject( params.data )
|
# if _.isObject( params.data )
|
||||||
for key, object of params.data
|
for key, object of params.data
|
||||||
|
if !params.refresh
|
||||||
App[ params.type ].refresh( object )
|
App[ params.type ].refresh( object )
|
||||||
|
|
||||||
# remember in store if not already requested from local storage
|
# remember in store if not already requested from local storage
|
||||||
|
@ -152,9 +154,13 @@ class _Singleton extends Spine.Module
|
||||||
# if App[type].exists( id ) && !callback
|
# if App[type].exists( id ) && !callback
|
||||||
if !force && App[type].exists( id )
|
if !force && App[type].exists( id )
|
||||||
data = App[type].find( id )
|
data = App[type].find( id )
|
||||||
|
data = @_fillUp( type, data )
|
||||||
if callback
|
if callback
|
||||||
callback( data )
|
callback( data )
|
||||||
|
console.log 'find', type, data
|
||||||
|
return data
|
||||||
else
|
else
|
||||||
|
console.log 'find not exists', type, data
|
||||||
if force
|
if force
|
||||||
@log 'Collection', 'debug', 'find forced to load!', type, id
|
@log 'Collection', 'debug', 'find forced to load!', type, id
|
||||||
else
|
else
|
||||||
|
@ -163,11 +169,11 @@ class _Singleton extends Spine.Module
|
||||||
|
|
||||||
# execute callback if record got loaded
|
# execute callback if record got loaded
|
||||||
col = @
|
col = @
|
||||||
App[type].one 'refresh', ->
|
App[type].one 'refresh', (record) ->
|
||||||
data = App.Collection.find( type, id )
|
data = App.Collection.find( type, id )
|
||||||
|
|
||||||
# load update to local storage
|
# load update to local storage
|
||||||
col.load( localStorage: true, type: type, data: data )
|
col.load( localStorage: false, type: type, data: record, refresh: true )
|
||||||
|
|
||||||
callback( data )
|
callback( data )
|
||||||
|
|
||||||
|
@ -177,6 +183,8 @@ class _Singleton extends Spine.Module
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
_fillUp: ( type, data ) ->
|
||||||
|
|
||||||
# users
|
# users
|
||||||
if type == 'User'
|
if type == 'User'
|
||||||
|
|
||||||
|
@ -189,8 +197,8 @@ class _Singleton extends Spine.Module
|
||||||
data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid']
|
data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid']
|
||||||
|
|
||||||
# set image url
|
# set image url
|
||||||
if data && !data['image']
|
if data && !data.image
|
||||||
data['image'] = 'http://placehold.it/48x48'
|
data.image = 'http://placehold.it/48x48'
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue