extension/sync.js
function (arrays, config, onDone) {
	
	var names = [];
		
	// load array's content from DB, if any	
	SR.DB.getArray(SR.Settings.DB_NAME_SYNC,
					function (result) {
						// NOTE: if array does not exist it'll return success with an empty array
						if (result === null || result.length === 0) {
							LOG.warn('no arrays found, cannot load', 'SR.Sync');
						}
						else {
							
							var array_limit = (typeof config.limit === 'number' ? config.limit : 0);
							
							LOG.sys('arrays exist, try to load (limit: ' + array_limit + ')', 'SR.Sync');
							
							for (var i=0; i < result.length; i++) {
								var record = result[i];
														
								var arr = arrays[record.name] = [];
																
								// load data (clone is better?)
								var limit = (record.data.length > array_limit ? array_limit : record.data.length);

								var start = record.data.length - limit;
																
								for (var j=0; j < limit; j++)
									arr[j] = UTIL.clone(record.data[start+j]);
								
								// override array's default behavior
								arr.push = l_push;
	
								// store array's name
								arr._name = record.name;
								
								// store last stored index (next index to store)
								arr._index = j;
								
								LOG.sys('[' + record.name + '] DB record length: ' + record.data.length + ' start: ' + start + ' actual limit: ' + limit + ' _index: ' + arr._index, 'SR.Sync');
																
								l_names[record.name] = arr;
								names.push(record.name);
							}															
						}
						UTIL.safeCall(onDone, names);
						
					}, 
					function (result) {
						UTIL.safeCall(onDone, names);
					}, 
					{});
}
function (arrays, config, onDone) {
	
	var names = [];
		
	// load array's content from DB, if any	
	SR.DB.getArray(SR.Settings.DB_NAME_SYNC,
					function (result) {
						// NOTE: if array does not exist it'll return success with an empty array
						if (result === null || result.length === 0) {
							LOG.warn('no arrays found, cannot load', 'SR.Sync');
						}
						else {
							
							var array_limit = (typeof config.limit === 'number' ? config.limit : 0);
							
							LOG.sys('arrays exist, try to load (limit: ' + array_limit + ')', 'SR.Sync');
							
							for (var i=0; i < result.length; i++) {
								var record = result[i];
														
								var arr = arrays[record.name] = [];
																
								// load data (clone is better?)
								var limit = (record.data.length > array_limit ? array_limit : record.data.length);

								var start = record.data.length - limit;
																
								for (var j=0; j < limit; j++)
									arr[j] = UTIL.clone(record.data[start+j]);
								
								// override array's default behavior
								arr.push = l_push;
	
								// store array's name
								arr._name = record.name;
								
								// store last stored index (next index to store)
								arr._index = j;
								
								LOG.sys('[' + record.name + '] DB record length: ' + record.data.length + ' start: ' + start + ' actual limit: ' + limit + ' _index: ' + arr._index, 'SR.Sync');
																
								l_names[record.name] = arr;
								names.push(record.name);
							}															
						}
						UTIL.safeCall(onDone, names);
						
					}, 
					function (result) {
						UTIL.safeCall(onDone, names);
					}, 
					{});
}
function ( arrays , config , onDone ) { var names = [ ] ; // load array's content from DB, if any	 SR . DB . getArray ( SR . Settings . DB_NAME_SYNC , function ( result ) { // NOTE: if array does not exist it'll return success with an empty array if ( result === null || result . length === 0 ) { LOG . warn ( 'no arrays found, cannot load' , 'SR.Sync' ) ; } else { var array_limit = ( typeof config . limit === 'number' ? config . limit : 0 ) ; LOG . sys ( 'arrays exist, try to load (limit: ' + array_limit + ')' , 'SR.Sync' ) ; for ( var i = 0 ; i < result . length ; i ++ ) { var record = result [ i ] ; var arr = arrays [ record . name ] = [ ] ; // load data (clone is better?) var limit = ( record . data . length > array_limit ? array_limit : record . data . length ) ; var start = record . data . length - limit ; for ( var j = 0 ; j < limit ; j ++ ) arr [ j ] = UTIL . clone ( record . data [ start + j ] ) ; // override array's default behavior arr . push = l_push ; // store array's name arr . _name = record . name ; // store last stored index (next index to store) arr . _index = j ; LOG . sys ( '[' + record . name + '] DB record length: ' + record . data . length + ' start: ' + start + ' actual limit: ' + limit + ' _index: ' + arr . _index , 'SR.Sync' ) ; l_names [ record . name ] = arr ; names . push ( record . name ) ; } } UTIL . safeCall ( onDone , names ) ; } , function ( result ) { UTIL . safeCall ( onDone , names ) ; } , { } ) ; }
load data from DB to an in-memory array returns a list of the names of arrays loaded
load data from DB to an in - memory array returns a list of the names of arrays loaded