The goog.ds.DataManager Class

goog.ds.DataManager
> goog.ds.DataNode

goog.ds.DataManager()

Create a DataManger

.addDataSource(ds, opt_autoload, opt_name)

Add a data source

ds {goog.ds.DataNode}
The data source.
opt_autoload {boolean=}
Whether to automatically load the data, defaults to false.
opt_name {string=}
Optional name, can also get name from the datasource.

.addIndexedListener(fn, dataPath, opt_id)

Adds an indexed listener. Indexed listeners allow for '*' in data paths. If a * exists, will match all values and return the matched values in an array to the callback. Currently uses a promiscuous match algorithm: Matches everything before the first '*', and then does a regex match for all of the returned events. Although this isn't optimized, it is still an improvement as you can collapse 100's of listeners into a single regex match

fn {Function}
Callback function, signature (dataPath, id, indexes).
dataPath {string}
Fully qualified data path.
opt_id {string=}
A value passed back to the listener when the dataPath is matched.

.addListener(fn, dataPath, opt_id)

Adds a listener Listeners should fire when any data with path that has dataPath as substring is changed. TODO(user) Look into better listener handling

fn {Function}
Callback function, signature function(dataPath, id).
dataPath {string}
Fully qualified data path.
opt_id {string=}
A value passed back to the listener when the dataPath is matched.

.aliasDataSource(name, dataPath)

Create an alias for a data path, very similar to assigning a variable. For example, you can set $CurrentContact -> $Request/Contacts[5], and all references to $CurrentContact will be procesed on $Request/Contacts[5]. Aliases will hide datasources of the same name.

name {string}
Alias name, must be a top level path ($Foo).
dataPath {string}
Data path being aliased.

.clearInstance()

Clears the global instance (for unit tests to reset state).

.fireDataChange(dataPath)

Fire a data change event to all listeners If the path matches the path of a listener, the listener will fire If your path is the parent of a listener, the listener will fire. I.e. if $Contacts/bob@bob.com changes, then we will fire listener for $Contacts/bob@bob.com/Name as well, as the assumption is that when a parent changes, all children are invalidated. If your path is the child of a listener, the listener may fire, depending on the ancestor depth. A listener for $Contacts might only be interested if the contact name changes (i.e. $Contacts doesn't fire on $Contacts/bob@bob.com/Name), while a listener for a specific contact might (i.e. $Contacts/bob@bob.com would fire on $Contacts/bob@bob.com/Name). Adding "/..." to a lisetener path listens to all children, and adding "/*" to a listener path listens only to direct children

dataPath {string}
Fully qualified data path.

.get(var_args)

Get the value of the node

var_args {...?}
Do not check arity of arguments, because some subclasses require args.
returns {Object}
The value of the node, or null if no value.

.getChildNode(name)

Gets a named child node of the current node

name {string}
The node name.
returns {goog.ds.DataNode}
The child node, or null if no node of this name exists.

.getChildNodeValue(name)

Gets the value of a child node

name {string}
The node name.
returns {*}
The value of the node, or null if no value or the child node doesn't exist.

.getChildNodes(opt_selector)

Gets all of the child nodes of the current node. Should return an empty DataNode list if no child nodes.

opt_selector {string=}
String selector to choose child nodes.
returns {goog.ds.DataNodeList}
The child nodes.

.getDataName()

Get the name of the node relative to the parent node

returns {string}
The name of the node.

.getDataPath()

Gets the a qualified data path to this node

returns {string}
The data path.

.getDataSource(name)

Gets a named child node of the current node.

name {string}
The node name.
returns {goog.ds.DataNode}
The child node, or null if no node of this name exists.

.getEventCount()

Get the total count of events fired (mostly for debugging)

returns {number}
Count of events.

.getInstance()

Get the global instance

returns {goog.ds.DataManager}
The data manager singleton.

.getListenerCount()

Get the total number of listeners (per expression listened to, so may be more than number of times addListener() has been called

returns {number}
Number of listeners.

.getLoadState()

Gets the state of the backing data for this node

returns {goog.ds.LoadState}
The state.

.isList()

Whether the value of this node is a homogeneous list of data

returns {boolean}
True if a list.

.load()

Load or reload the backing data for this node only loads datasources flagged with autoload

.removeIndexedListeners(fn, opt_dataPath, opt_id)

Removes indexed listeners with a given callback function, and optional matching datapath and matching id.

fn {Function}
Callback function, signature function(dataPath, id).
opt_dataPath {string=}
Fully qualified data path.
opt_id {string=}
A value passed back to the listener when the dataPath is matched.

.removeListeners(fn, opt_dataPath, opt_id)

Removes listeners with a given callback function, and optional matching dataPath and matching id

fn {Function}
Callback function, signature function(dataPath, id).
opt_dataPath {string=}
Fully qualified data path.
opt_id {string=}
A value passed back to the listener when the dataPath is matched.

.runWithoutFiringDataChanges(callback)

Disables the sending of all data events during the execution of the given callback. This provides a way to avoid useless notifications of small changes when you will eventually send a data event manually that encompasses them all. Note that this function can not be called reentrantly.

callback {Function}
Zero-arg function to execute.

.set(value)

Set the value of the node

value {*}
The new value of the node.

.setChildNode(name, value)

Inherited from goog.ds.DataNode .

Sets a named child node of the current node.

name {string}
The node name.
value {Object}
The value to set, can be DataNode, object, property, or null. If value is null, removes the child node.
returns {Object}
The child node, if the node was set.

.setDataName(name)

Inherited from goog.ds.DataNode .

Set the name of the node relative to the parent node

name {string}
The name of the node.