Home Reference Source Repository
import CollectionShadow from 'f.lux/src/collection/CollectionShadow.js'
public class | source

CollectionShadow

Extends:

Shadow → CollectionShadow

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 models
  • isPaging() - gets if a paging request is outstanding (only one paging request per collection allowed at one time)
  • hasMorePages() - does the endpoint have additional models
  • nextOffset() - gets the offset for the next paging request
  • resetPaging() - resets the internal paging variables
  • setLimit() - change the number of models requested with each fetchNext() request

See:

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

Gets if a fetching operation that will replace ALL models is in progress.

public get

id: string: *

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

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
public

add(state: object, mergeOp: string): *

Synchronously adds a new model object to the collection.

public

addModel(state: *, mergeOp: *): *

public

addModels(models: array, mergeOp: string, syncOp: boolean)

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

create(model: Object): Promise

Combines an CollectionShadow#add and CollectionShadow#save actions.

public

destroy(id: *): Promise

Permantently deletes the model with the endpoint and removes it from the collection.

public

Gets an iterator with [ID, model] paris.

public

every(iteratee: *, context: *): boolean

Tests whether all elements in the array pass the test implemented by the provided function.

public

fetch(filter: *, mergeOp: string): Promise

Fetches all the models from the endpoint.

public

fetchNext(mergeOp: string): Promise

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

find(id: *): Promise

Gets a model by ID.

public

findModel(iteratee: *, context: object): *

Gets the first model that satisfies the provided testing function.

public

forEach(iteratee: *, context: object)

Executes a provided function once for each array element.

public

get(id: *): Object

Gets a model by ID.

public

groupBy(callback: *, context: *)

Inspired by Lodash groupBy() method.

public

has(id: *): boolean

Gets if the collection contains a matching model.

public

Gets if additional paging calls will return additional results.

public

Sets whether auto-checkpointing is enabled.

public

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

map(iteratee: *, context: object): *

Creates a new array with the results of calling a provided function on every element in this collection.

public

reduce(iteratee: *, acc: *, context: object): *

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

Sets whether auto-checkpointing should be enabled.

public

setEndpoint(endPoint: *)

public

setLimit(limit: number)

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

some(iteratee: *, context: object): boolean

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

Gets an array containing each model iDs.

Inherited Summary

From class Shadow
public

[_impl]: *

public

$(): Access

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#constructor

Params:

NameTypeAttributeDescription
impl *

Public Members

public [_cache]: {} source

public get endpoint: Object: * source

Gets the endpoint for accessing the remote data source.

Return:

Object

public get fetching: * source

Gets if a fetching operation that will replace ALL models is in progress.

public get id: string: * source

Gets the endpoint ID, which for RestEndpointProperty is its URL.

Return:

string

public get limit: * source

Gets the number of models to fetch with each paging request.

public get nextOffset: * source

Gets the offset for the next paging request.

public get paging: * source

Gets if a paging operation (CollectionProperty#fetchNext) call is in progress.

public get size: * source

Gets the number of models being managed by the collection

Public Methods

public [Symbol.iterator](): * source

Return:

*

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.

Params:

NameTypeAttributeDescription
state object

the json model to add to the collection

mergeOp string
  • optional
  • default: REPLACE_OPTION

one of DEFAULTS_OPTION, MERGE_OPTION, or REPLACE_OPTION and specifies how to combine an existing model with a matching ID with a newly retrieved model.

Return:

*

the object's ID. And ID is assigned if the 'id' parameter was not set and it could not be found in the state parameter.

public addModel(state: *, mergeOp: *): * source

Params:

NameTypeAttributeDescription
state *
mergeOp *
  • optional
  • default: REPLACE_OPTION

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:

NameTypeAttributeDescription
models array

array of model values

mergeOp string
  • optional
  • default: REPLACE_OPTION

one of DEFAULTS_OPTION, MERGE_OPTION, or REPLACE_OPTION and specifies how to combine an existing model with a matching ID with a newly retrieved model.

syncOp boolean
  • optional
  • default: true

sets the synced flag to true if this parameter is true

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:

NameTypeAttributeDescription
model Object

the json data

Return:

Promise

resolves with the f.lux shadow state for the new model

public destroy(id: *): Promise source

Permantently deletes the model with the endpoint and removes it from the collection.

Params:

NameTypeAttributeDescription
id *

the model ID to delete

Return:

Promise

resolves with the ID for the removed mdoel

public entries(): Array source

Gets an iterator with [ID, model] paris.

Return:

Array

public every(iteratee: *, context: *): boolean source

Tests whether all elements in the array pass the test implemented by the provided function.

Params:

NameTypeAttributeDescription
iteratee *
context *

Return:

boolean

public fetch(filter: *, mergeOp: string): Promise source

Fetches all the models from the endpoint.

Params:

NameTypeAttributeDescription
filter *
  • optional
  • default: null

filter object created using the endpoint.

mergeOp string
  • optional
  • default: REPLACE_OPTION

one of DEFAULTS_OPTION, MERGE_OPTION, or REPLACE_OPTION and specifies how to combine an existing model with a matching ID with a newly retrieved model.

Return:

Promise

resolves with the json models from the endpoint

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:

NameTypeAttributeDescription
mergeOp string
  • optional
  • default: REPLACE_OPTION

one of DEFAULTS_OPTION, MERGE_OPTION, or REPLACE_OPTION and specifies how to combine an existing model with a matching ID with a newly retrieved model.

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
id *

the model ID

Return:

Promise

reolves with the model or undefined if one is not found

public findModel(iteratee: *, context: object): * source

Gets the first model that satisfies the provided testing function.

Params:

NameTypeAttributeDescription
iteratee *

Function to execute on each value in the array, taking three arguments: element, ID, and the collection reference.

context object
  • optional

object to use as this when executing callback

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:

NameTypeAttributeDescription
iteratee *

Function to execute on each value in the array, taking three arguments: element, ID, and the collection reference.

context object
  • optional

object to use as this when executing callback

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:

NameTypeAttributeDescription
id *

the model ID

Return:

Object

the model or undefined if one is not found

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:

NameTypeAttributeDescription
callback *
context *

See:

public has(id: *): boolean source

Gets if the collection contains a matching model.

Params:

NameTypeAttributeDescription
id *

the model ID

Return:

boolean

public hasMorePages(): * source

Gets if additional paging calls will return additional results.

Return:

*

public isAutocheckpoint(): boolean source

Sets whether auto-checkpointing is enabled.

Return:

boolean

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:

NameTypeAttributeDescription
id *

Return:

*

public keys(): Iterator source

Gets an iterator containing each model IDs.

Return:

Iterator

public keysArray(): Array source

Gets an array containing each model iDs.

Return:

Array

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:

NameTypeAttributeDescription
iteratee *

Function that produces an element of the new array, taking three arguments: element, ID, and the collection reference.

context object
  • optional

object to use as this when executing callback

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:

NameTypeAttributeDescription
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
  • optional

object to use as this when executing callback

Return:

*

public remove(id: *): * source

Synchronously removes the model from the collection without performing an endpoint operation.

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
auto boolean

true to enable.

public setEndpoint(endPoint: *) source

Sets the CollectionProperty#endpoint.

Params:

NameTypeAttributeDescription
endPoint *

public setLimit(limit: number) source

Sets the number of models to request with each paging request. The default paging size is 50.

Params:

NameTypeAttributeDescription
limit number

public setModels(models: array) source

Bulk replaces current models with an array of new models.

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
iteratee *

Function to test for each element, taking three arguments: element, ID, and the collection reference.

context object
  • optional

object to use as this when executing callback

Return:

boolean

public sortBy(iteratee: ...*): * source

Params:

NameTypeAttributeDescription
iteratee ...*

Return:

*

public values(): Iterator source

Gets an iterator containing each f.lux shadow state model.

Return:

Iterator

public valuesArray(): Array source

Gets an array containing each model iDs.

Return:

Array