new LocalDataStore()
Methods
doFilterAndSort(cachedData, ubRequest) → *
static
Perform local filtration and sorting of data array according to ubRequest whereList & order list
Arguments:
-
cachedData
(TubCachedData)
 Data, retrieved from cache
-
ubRequest
(TubSelectRequest)
 Initial server request
byID(cachedData, IDValue)
static
Just a helper for search cached data by row ID
Arguments:
-
cachedData
(TubCachedData)
 Data, retrieved from cache
-
IDValue
(Number)
 row ID.
doFiltration(cachedData, ubRequest) → Array.<Array>
protected
static
Apply ubRequest.whereList to data array and return new array contain filtered data
Arguments:
-
cachedData
(TubCachedData)
 Data, retrieved from cache
-
ubRequest
(TubSelectRequest)
doSorting(filteredArray, cachedData, ubRequest)
protected
static
Apply ubRequest.orderList to inputArray (inputArray is modified)
Arguments:
-
filteredArray
(Array.<Array>)
-
cachedData
(TubCachedData)
-
ubRequest
(Object)
selectResultToArrayOfObjects(selectResult, fieldAliasopt) → Array.<*>
static
Transform result of UBConnection#select
response
from Array of Array representation to Array of Object.
LocalDataStore.selectResultToArrayOfObjects({resultData: {
data: [['row1_attr1Val', 1], ['row2_attr2Val', 22]],
fields: ['attrID.name', 'attr2']}
});
// result is:
// [{"attrID.name": "row1_attr1Val", attr2: 1},
// {"attrID.name": "row2_attr2Val", attr2: 22}
// ]
// object keys simplify by passing fieldAliases
LocalDataStore.selectResultToArrayOfObjects({resultData: {
data: [['row1_attr1Val', 1], ['row2_attr2Val', 22]],
fields: ['attrID.name', 'attr2']}
}, {'attrID.name': 'attr1Name'});
// result is:
// [{attr1Name: "row1_attr1Val", attr2: 1},
// {attr1Name: "row2_attr2Val", attr2: 22}
// ]
Arguments:
-
selectResult
(Object)
-
[fieldAlias]
(Object)
 Optional object to change attribute names during transform array to object
flatten(requestedFieldList, cachedData)
static
Flatten cached data (or result of LocalDataStore#doFilterAndSort
.resultData )
to Object expected by TubDataStore#initFromJSON
compact format (faster when [{}..] format).
//consider we have cached data in variable filteredData.resultData
// to initialize dataStore with cached data:
mySelectMethod = function(ctxt){
var fieldList = ctxt.mParams.fieldList;
resp = LocalDataStore.flatten(fieldList, filteredData.resultData);
ctxt.dataStore.initFromJSON(resp);
}
cachedData may contain more field or field in order not in requestedFieldList - in this case we use expectedFieldList
Arguments:
-
requestedFieldList
(Array.<string>)
 Array of attributes to transform to. Can be ['*'] - in this case we return all cached attributes
-
cachedData
(TubCachedData)
arrayOfObjectsToSelectResult(arrayOfObject, attributeNames) → Array.<Array>
static
Reverse conversion to LocalDataStore#selectResultToArrayOfObjects
Transform array of object to array of array using passed attributes array
LocalDataStore.arrayOfObjectsToSelectResult([{a: 1, b: 'as'}, {b: 'other', a: 12}], ['a', 'b']);
// result is: [[1,"as"],[12,"other"]]
Arguments:
-
arrayOfObject
(Array.<Object>)
-
attributeNames
(Array.<String>)
cachedData
(TubCachedData)
 Data, retrieved from cache
ubRequest
(TubSelectRequest)
 Initial server request
cachedData
(TubCachedData)
 Data, retrieved from cache
IDValue
(Number)
 row ID.
cachedData
(TubCachedData)
 Data, retrieved from cache
ubRequest
(TubSelectRequest)
filteredArray
(Array.<Array>)
cachedData
(TubCachedData)
ubRequest
(Object)
Transform result of UBConnection#select
response
from Array of Array representation to Array of Object.
LocalDataStore.selectResultToArrayOfObjects({resultData: {
data: [['row1_attr1Val', 1], ['row2_attr2Val', 22]],
fields: ['attrID.name', 'attr2']}
});
// result is:
// [{"attrID.name": "row1_attr1Val", attr2: 1},
// {"attrID.name": "row2_attr2Val", attr2: 22}
// ]
// object keys simplify by passing fieldAliases
LocalDataStore.selectResultToArrayOfObjects({resultData: {
data: [['row1_attr1Val', 1], ['row2_attr2Val', 22]],
fields: ['attrID.name', 'attr2']}
}, {'attrID.name': 'attr1Name'});
// result is:
// [{attr1Name: "row1_attr1Val", attr2: 1},
// {attr1Name: "row2_attr2Val", attr2: 22}
// ]
selectResult
(Object)
[fieldAlias]
(Object)
 Optional object to change attribute names during transform array to object
LocalDataStore#doFilterAndSort
.resultData )
to Object expected by TubDataStore#initFromJSON
compact format (faster when [{}..] format).
//consider we have cached data in variable filteredData.resultData
// to initialize dataStore with cached data:
mySelectMethod = function(ctxt){
var fieldList = ctxt.mParams.fieldList;
resp = LocalDataStore.flatten(fieldList, filteredData.resultData);
ctxt.dataStore.initFromJSON(resp);
}
cachedData may contain more field or field in order not in requestedFieldList - in this case we use expectedFieldList
requestedFieldList
(Array.<string>)
 Array of attributes to transform to. Can be ['*'] - in this case we return all cached attributes
cachedData
(TubCachedData)
Reverse conversion to LocalDataStore#selectResultToArrayOfObjects
Transform array of object to array of array using passed attributes array
LocalDataStore.arrayOfObjectsToSelectResult([{a: 1, b: 'as'}, {b: 'other', a: 12}], ['a', 'b']);
// result is: [[1,"as"],[12,"other"]]
arrayOfObject
(Array.<Object>)
attributeNames
(Array.<String>)