kvcobj
v0.1.0-6
Published
Key-value coding for javascript objects.
Downloads
5
Readme
KVCObject
Key-value coding for javascript objects. Gives access to values in object trees via keypaths. Emits update events as they come, with minimal changesets. Good for finding deltas for new versions of objects, and linking views to models.
Public API
Methods
(constructor)([< object >options])
Creates and returns a new KVCObject.
Valid options:- delimiter - string - The string to use as delimiter between keys. Default: '.'
setObject(< object >object, [< bool >silent]) - (void)
Sets the current root, overwriting the existing root. If this leads to a change of the object, anupdate
(and possibly also acreate
ordelete
, see below) event will be triggered, unlesssilent
is set totrue
.getObject() - (object)
Returns the current root as a normal object.setObjectForKeypath(< object >object, < string >rootKeypath, [< bool >silent]) - (void)
Sets all values ofobject
, whererootKeypath
will be the keypath to the root of the object. If this leads to a change of the object, anupdate
(and possibly also acreate
ordelete
, see below) event will be triggered, unlesssilent
is set totrue
.getObjectForKeypath(< string >keypath) - (object)
Returns the object fromkeypath
.setValueForKeypath(< non-object >value, < string >keypath, [< bool >silent]) - (void)
Setsvalue
atkeypath
. If this leads to a change of the object, anupdate
(and possibly also acreate
ordelete
, see below) event will be triggered, unlesssilent
is set totrue
.getValueForKeypath(< string >keypath) - (non-object)
Returns the value atkeypath
.commit() - (void)
Commits uncommited changes made withsilent
set totrue
. This leads to change events being emitted.
Events
create(< object >created)
Emitted when a value (or a set of values) is set for a keypath (or a set of keypaths) for the first time.created
is an object with the new keypaths as keys and their corresponding values as values
Note: a newcreate
event will be emitted when the value for a keypath is deleted (set toundefined
) and the reset to a value
Note: a matchingupdate
event will also be emitted for eachcreate
eventupdate(< object >updated)
Emitted when a value (or a set of values) is changed for a keypath (or a set of keypaths).updated
is an object with the updated keypaths as keys and corresponding values as values
Note: anupdate
event will be emitted even if there is no previous value for the keypathdelete(< object >deleted)
Emitted when a value (or a set of values) is deleted (or set toundefined
) for a keypath (or a set of keypaths).deleted
is an object with the deleted keypaths as keys and corresponding values as values
Note: a matchingupdate
event will also be emitted for eachdelete
event