cacheMixin

cacheMixin

Source:
Author:
  • ariel.wexler@vecna.com, kent.willis@vecna.com
See:

Custom additions to the Backbone Collection object.

  • safe disposal methods for memory + event management
  • special functional overrides to support ID registration for different views

Methods

(static) constructor(optionsopt)

Source:

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.

(static) createPrivateCollection(guid) → {PrivateCollection}

Source:

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

(static) fetch(options)

Source:

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

(static) fetchByIds(fetchByIdsOptionsopt) → {Promise}

Source:

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

(static) getAllRequestedIds() → {Array}

Source:

Return the list of Ids requested by this collection

Returns:

the corresponding requested Ids

Type
Array

(static) getRequesterIds(the) → {Array}

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

(static) getRequesterIdsAsDictionary(guid) → {Object}

Source:

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

(static) getRequesters() → {Array}

Source:

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

(static) registerIds(newIds, guid)

Source:

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

(static) removeRequester(guid)

Source:

Removes a requester from this cache. No longer receives updates

Parameters:
Name Type Description
guid string

the global unique id of the requester