Collection

Collection

new Collection()

Source:
Mixes In:
Author:
  • kent.willis@vecna.com
See:

Generic Collection

Extends

Members

pollTimeoutId

Source:
Mixes In:
Properties:
Name Type Description
pollTimeoutId number

The id from when setTimeout was called to start polling.

Methods

constructor(optionsopt)

Source:
Mixes In:

The constructor constructor / initialize method for collections.
Allocate new memory for the local references if they
were null when this method was called.

Parameters:
Name Type Attributes Description
options Object <optional>

optional options object

Properties
Name Type Attributes Default Description
fetchHttpAction string <optional>
'POST'

http action used to get objects by ids

getByIdsUrl string <optional>
'/ids'

path appended to collection.url to get objects by a list of ids

fetchUsingTrackedIds boolean <optional>
true

if set to false, cache.fetch() will not pass to fetchByIds with current tracked ids
but will rather call the default fetch method.

createPrivateCollection(guid) → {PrivateCollection}

Source:
Mixes In:

Used to return a collection of desired models given the requester object.
Binds a custom "resized" event to the private collections.
Overrides the fetch method to call the parent collection's fetchByIds method.
Overrides the registerIds method to redirect to its parent collection.

Parameters:
Name Type Description
guid string

Identifier for the requesting view

Returns:

an new empty collection of the same type as "this"

Type
PrivateCollection

dispose()

Source:

Will abolish all listeners and events that are hooked
to this collection.

fetch(options)

Source:
Mixes In:

Overrides the base fetch call if this.fetchUsingTrackedIds is true
Calling fetch from the cache will fetch the tracked ids if fetchUsingTrackedIds is set to true, otherwise
it will pass through to the default fetch.

Parameters:
Name Type Description
options Object

fetchByIds(fetchByIdsOptionsopt) → {Promise}

Source:
Mixes In:

A custom fetch operation to only fetch the requested Ids.

Parameters:
Name Type Attributes Description
fetchByIdsOptions <optional>

argument fetchByIdsOptions

Properties
Name Type Attributes Default Description
idsToFetch Array <optional>
collection.collectionTrackedIds

A list of request Ids, will default to current tracked ids

setOptions Object <optional>

if a set is made, then the setOptions will be passed into the set method

Returns:

the promise of the fetch

Type
Promise

filterDefault() → {Collection}

Source:

The default filter. Always returns itself.

Returns:

a new instance of this collection

Type
Collection

getAllRequestedIds() → {Array}

Source:
Mixes In:

Return the list of Ids requested by this collection

Returns:

the corresponding requested Ids

Type
Array

getLoadedOncePromise() → {Promise}

Source:
Mixes In:
Returns:

a promise that will resolve when the model/collection has loaded for the first time

Type
Promise

getRequesterIds(the) → {Array}

Source:
Mixes In:
Parameters:
Name Type Description
the string

global unique id of the requester

Returns:

an array of the ids the requester with the guid has requested

Type
Array

getRequesterIdsAsDictionary(guid) → {Object}

Source:
Mixes In:

This method is used for quick look up of a certain id within the list of requested ids

Parameters:
Name Type Description
guid string

the global unique id of the requester

Returns:

an dictionary of id -> id of the requester ids for a given requester.

Type
Object

getRequesters() → {Array}

Source:
Mixes In:

NOTE: this methods returns only the guids for requester collections that are currently tracking ids
TODO: should this return just the knownPrivateCollections

Returns:

an array of the all requesters in the form of their GUID's

Type
Array

hasLoadedOnce() → {boolean}

Source:
Mixes In:
Returns:

true if this model/collection has ever loaded from a fetch call

Type
boolean

isLoading() → {boolean}

Source:
Mixes In:
Returns:

true if this model/collection is currently loading new values from the server

Type
boolean

isPolling()

Source:
Mixes In:

Returns true if the poll is active

polledFetch()

Source:
Mixes In:

By default, the polled fetching operation is routed directly
to backbone's fetch all.

registerIds(newIds, guid)

Source:
Mixes In:

Registers a list of Ids that a particular object cares about and pushes
any cached models its way.

This method intelligently updates the "_requestedIds" field to contain all unique
requests for Ids to be fetched. Furthermore, the "polledFetch" method
is overriden such that it no longer routes through Backbone's fetch all,
but rather a custom "fetchByIds" method.

Parameters:
Name Type Description
newIds Array

New ids to register under the requester

guid string

The GUID of the object that wants the ids

removeRequester(guid)

Source:
Mixes In:

Removes a requester from this cache. No longer receives updates

Parameters:
Name Type Description
guid string

the global unique id of the requester

startPolling(pollInterval)

Source:
Mixes In:

Starts polling Model/Collection by calling fetch every pollInterval.
Note: Each Model/Collection will only allow a singleton of polling to occur so
as not to have duplicate threads updating Model/Collection.

Parameters:
Name Type Description
pollInterval Integer

interval between each poll in ms.

stopPolling()

Source:
Mixes In:

Stops polling Model and clears all Timeouts.