From 0d20c7d41302707273d7f3eb30fd238fcb9c8ce3 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 1 Oct 2012 20:56:46 +0200 Subject: [PATCH] Improved load ob objects in local storage / race condition during init/overwrite of new already loaded data. --- app/assets/javascripts/app/lib/collection.js.coffee | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/app/lib/collection.js.coffee b/app/assets/javascripts/app/lib/collection.js.coffee index d4f323562..8f71294f3 100644 --- a/app/assets/javascripts/app/lib/collection.js.coffee +++ b/app/assets/javascripts/app/lib/collection.js.coffee @@ -76,23 +76,27 @@ class _Singleton return if _.isEmpty( params.data ) + localStorage = params.localStorage + if _.isArray( params.data ) for object in params.data # console.log( 'load ARRAY', object) - App[params.type].refresh( object, options: { clear: true } ) + if !localStorage || localStorage && !App[ params.type ].exists( object['id'] ) + App[ params.type ].refresh( object, options: { clear: true } ) # remember in store if not already requested from local storage - if !params.localStorage + if !localStorage App.Store.write( 'collection::' + params.type + '::' + object.id, { type: params.type, localStorage: true, data: [ object ] } ) return # if _.isObject( params.data ) for key, object of params.data # console.log( 'load OB', object) - App[params.type].refresh( object, options: { clear: true } ) + if !localStorage || localStorage && !App[ params.type ].exists( object['id'] ) + App[ params.type ].refresh( object, options: { clear: true } ) # remember in store if not already requested from local storage - if !params.localStorage + if !localStorage App.Store.write( 'collection::' + params.type + '::' + object.id, { type: params.type, localStorage: true, data: [ object ] } ) find: ( type, id, callback ) ->