CollectionShadow
Extends:
Shadow api for the CollectionProperty
.
Basic functions
add(state, mergeOp)
all()
clear()</li> <li>
create(model)</li> <li>
destroy(id)</li> <li>
fetch(filter, mergeOp)</li> <li>
find(id)</li> <li>
get(id)</li> <li>
has(id)</li> <li>
remove(id)`
Utility functions
entries()
every(iteratee, context)
filter(iteratee, context)
groupBy(callback, context)
keys()
map(iteratee, context)
reduce(iteratee, acc, context)
some(iteratee, context)
sortBy(...iteratee)
values()
Paging function
fetchNext()
- gets the next group of modelsisPaging()
- gets if a paging request is outstanding (only one paging request per collection allowed at one time)hasMorePages()
- does the endpoint have additional modelsnextOffset()
- gets the offset for the next paging requestresetPaging()
- resets the internal paging variablessetLimit()
- change the number of models requested with eachfetchNext()
request
Constructor Summary
Public Constructor | ||
public |
constructor(impl: *) |
Member Summary
Public Members | ||
public |
[_cache]: {} |
|
public get |
Gets the endpoint for accessing the remote data source. |
|
public get |
fetching: * Gets if a fetching operation that will replace ALL models is in progress. |
|
public get |
Gets the endpoint ID, which for RestEndpointProperty is its URL. |
|
public get |
limit: * Gets the number of models to fetch with each paging request. |
|
public get |
nextOffset: * Gets the offset for the next paging request. |
|
public get |
paging: * Gets if a paging operation (CollectionProperty#fetchNext) call is in progress. |
|
public get |
size: * Gets the number of models being managed by the collection |
Method Summary
Public Methods | ||
public |
[Symbol.iterator](): * |
|
public |
Synchronously adds a new model object to the collection. |
|
public |
addModel(state: *, mergeOp: *): * |
|
public |
Bulk adds multiple models. |
|
public |
all(): array Gets the shadow models currently managed by the collection. |
|
public |
clear() Removes all models from the collection and marks the collection as having not synched with the endpoint. |
|
public |
Combines an CollectionShadow#add and CollectionShadow#save actions. |
|
public |
Permantently deletes the model with the endpoint and removes it from the collection. |
|
public |
Gets an iterator with [ID, model] paris. |
|
public |
Tests whether all elements in the array pass the test implemented by the provided function. |
|
public |
Fetches all the models from the endpoint. |
|
public |
Fetches the next set of models from the endpoint. |
|
public |
filter(iteratee: *, context: *): * Creates an array with all elements that pass the test implemented by the provided function. |
|
public |
Gets a model by ID. |
|
public |
Gets the first model that satisfies the provided testing function. |
|
public |
Executes a provided function once for each array element. |
|
public |
Gets a model by ID. |
|
public |
groupBy(callback: *, context: *) Inspired by Lodash groupBy() method. |
|
public |
Gets if the collection contains a matching model. |
|
public |
hasMorePages(): * Gets if additional paging calls will return additional results. |
|
public |
Sets whether auto-checkpointing is enabled. |
|
public |
isConnected(): * Gets if the collection is active (has a shadow) and an endpoint. |
|
public |
isNew(id: *): * Gets if a model has never been persisted to the endpoint. |
|
public |
keys(): Iterator Gets an iterator containing each model IDs. |
|
public |
Gets an array containing each model iDs. |
|
public |
Creates a new array with the results of calling a provided function on every element in this collection. |
|
public |
Applies a function against an accumulator and each value of the collection to reduce it to a single value. |
|
public |
remove(id: *): * Synchronously removes the model from the collection without performing an endpoint operation. |
|
public |
Resets all dirty models to their last checkpoint and removes all unsaved models. |
|
public |
setAutocheckpoint(auto: boolean) Sets whether auto-checkpointing should be enabled. |
|
public |
setEndpoint(endPoint: *) Sets the CollectionProperty#endpoint. |
|
public |
Sets the number of models to request with each paging request. |
|
public |
setModels(models: array) Bulk replaces current models with an array of new models. |
|
public |
Tests whether some element in the array passes the test implemented by the provided function. |
|
public |
sortBy(iteratee: ...*): * |
|
public |
values(): Iterator Gets an iterator containing each f.lux shadow state model. |
|
public |
valuesArray(): Array Gets an array containing each model iDs. |
Inherited Summary
From class Shadow | ||
public |
[_impl]: * |
|
public |
Gets the Access object for obtaining information about a property. |
|
public |
Gets the Property managing this shadow state property. |
|
public |
Gets the actual state property being proxied by this shadow state property. |
|
public |
toString(): * |
Public Constructors
public constructor(impl: *) source
Override:
Shadow#constructorParams:
Name | Type | Attribute | Description |
impl | * |
Public Members
public [_cache]: {} source
public get fetching: * source
Gets if a fetching operation that will replace ALL models is in progress.
public get paging: * source
Gets if a paging operation (CollectionProperty#fetchNext) call is in progress.
Public Methods
public add(state: object, mergeOp: string): * source
Synchronously adds a new model object to the collection. Call model.$().save()
to persist the newly
added object.
Return:
* | the object's ID. And ID is assigned if the 'id' parameter was not set and it could not
be found in the |
public addModel(state: *, mergeOp: *): * source
Params:
Name | Type | Attribute | Description |
state | * | ||
mergeOp | * |
|
Return:
* |
public addModels(models: array, mergeOp: string, syncOp: boolean) source
Bulk adds multiple models. Models must have an ID as it is assumed they have been previously saved.
Params:
Name | Type | Attribute | Description |
models | array | array of model values |
|
mergeOp | string |
|
one of |
syncOp | boolean |
|
sets the |
public all(): array source
Gets the shadow models currently managed by the collection.
Return:
array | all models being managed by the collection |
public clear() source
Removes all models from the collection and marks the collection as having not synched with the endpoint.
public create(model: Object): Promise source
Combines an CollectionShadow#add and CollectionShadow#save actions.
Params:
Name | Type | Attribute | Description |
model | Object | the json data |
public destroy(id: *): Promise source
Permantently deletes the model with the endpoint and removes it from the collection.
Params:
Name | Type | Attribute | Description |
id | * | the model ID to delete |
public every(iteratee: *, context: *): boolean source
Tests whether all elements in the array pass the test implemented by the provided function.
Params:
Name | Type | Attribute | Description |
iteratee | * | ||
context | * |
public fetch(filter: *, mergeOp: string): Promise source
Fetches all the models from the endpoint.
Params:
Name | Type | Attribute | Description |
filter | * |
|
filter object created using the endpoint. |
mergeOp | string |
|
one of |
public fetchNext(mergeOp: string): Promise source
Fetches the next set of models from the endpoint. This method differs from
CollectionProperty#fetch by passing offset
and limit
filter criteria to the
endpoint.
Params:
Name | Type | Attribute | Description |
mergeOp | string |
|
one of |
Return:
Promise | resolves with a single argument of an array of model json objects as returned from the endpoint. |
public filter(iteratee: *, context: *): * source
Creates an array with all elements that pass the test implemented by the provided function.
Params:
Name | Type | Attribute | Description |
iteratee | * | ||
context | * |
Return:
* |
public find(id: *): Promise source
Gets a model by ID. The method looks for a matching model in the collection. If one is not found then one is requested from the endpoint.
Params:
Name | Type | Attribute | Description |
id | * | the model ID |
public findModel(iteratee: *, context: object): * source
Gets the first model that satisfies the provided testing function.
Params:
Name | Type | Attribute | Description |
iteratee | * | Function to execute on each value in the array, taking three arguments: element, ID, and the collection reference. |
|
context | object |
|
object to use as |
Return:
* | the model or undefined if one is not found |
public forEach(iteratee: *, context: object) source
Executes a provided function once for each array element.
Params:
Name | Type | Attribute | Description |
iteratee | * | Function to execute on each value in the array, taking three arguments: element, ID, and the collection reference. |
|
context | object |
|
object to use as |
public get(id: *): Object source
Gets a model by ID. The method looks for a matching model in the collection and never looks for one remotely through the endpoint.
Params:
Name | Type | Attribute | Description |
id | * | the model ID |
public groupBy(callback: *, context: *) source
Inspired by Lodash groupBy() method.
Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The order of grouped values is determined by the order they occur in collection. The corresponding value of each key is an array of elements responsible for generating the key. The iteratee is invoked with one argument: (value).
Params:
Name | Type | Attribute | Description |
callback | * | ||
context | * |
public has(id: *): boolean source
Gets if the collection contains a matching model.
Params:
Name | Type | Attribute | Description |
id | * | the model ID |
public hasMorePages(): * source
Gets if additional paging calls will return additional results.
Return:
* |
public isConnected(): * source
Gets if the collection is active (has a shadow) and an endpoint.
Return:
* |
public isNew(id: *): * source
Gets if a model has never been persisted to the endpoint.
Params:
Name | Type | Attribute | Description |
id | * |
Return:
* |
public map(iteratee: *, context: object): * source
Creates a new array with the results of calling a provided function on every element in this collection.
Params:
Name | Type | Attribute | Description |
iteratee | * | Function that produces an element of the new array, taking three arguments: element, ID, and the collection reference. |
|
context | object |
|
object to use as |
Return:
* |
public reduce(iteratee: *, acc: *, context: object): * source
Applies a function against an accumulator and each value of the collection to reduce it to a single value.
Params:
Name | Type | Attribute | Description |
iteratee | * | Function to execute on each value in the array, taking four arguments: accumulator, element, ID, and the collection reference. |
|
acc | * | the initial accumulator value |
|
context | object |
|
object to use as |
Return:
* |
public remove(id: *): * source
Synchronously removes the model from the collection without performing an endpoint operation.
Params:
Name | Type | Attribute | Description |
id | * | the model id or cid |
Return:
* |
public resetToLastEndpointState() source
Resets all dirty models to their last checkpoint and removes all unsaved models.
public setAutocheckpoint(auto: boolean) source
Sets whether auto-checkpointing should be enabled.
Params:
Name | Type | Attribute | Description |
auto | boolean |
|
public setEndpoint(endPoint: *) source
Sets the CollectionProperty#endpoint.
Params:
Name | Type | Attribute | Description |
endPoint | * |
public setLimit(limit: number) source
Sets the number of models to request with each paging request. The default paging size is 50.
Params:
Name | Type | Attribute | Description |
limit | number |
public setModels(models: array) source
Bulk replaces current models with an array of new models.
Params:
Name | Type | Attribute | Description |
models | array | array of model values |
public some(iteratee: *, context: object): boolean source
Tests whether some element in the array passes the test implemented by the provided function.
Params:
Name | Type | Attribute | Description |
iteratee | * | Function to test for each element, taking three arguments: element, ID, and the collection reference. |
|
context | object |
|
object to use as |
public sortBy(iteratee: ...*): * source
Params:
Name | Type | Attribute | Description |
iteratee | ...* |
Return:
* |
public values(): Iterator source
Gets an iterator containing each f.lux shadow state model.
Return:
Iterator |