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.
-
(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 acreateordelete, see below) event will be triggered, unlesssilentis set totrue. -
getObject() - (object)
Returns the current root as a normal object. -
setObjectForKeypath(< object >object, < string >rootKeypath, [< bool >silent]) - (void)
Sets all values ofobject, whererootKeypathwill be the keypath to the root of the object. If this leads to a change of the object, anupdate(and possibly also acreateordelete, see below) event will be triggered, unlesssilentis set totrue. -
getObjectForKeypath(< string >keypath) - (object)
Returns the object fromkeypath. -
setValueForKeypath(< non-object >value, < string >keypath, [< bool >silent]) - (void)
Setsvalueatkeypath. If this leads to a change of the object, anupdate(and possibly also acreateordelete, see below) event will be triggered, unlesssilentis set totrue. -
getValueForKeypath(< string >keypath) - (non-object)
Returns the value atkeypath. -
commit() - (void)
Commits uncommited changes made withsilentset totrue. This leads to change events being emitted.
-
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.
createdis an object with the new keypaths as keys and their corresponding values as values
Note: a newcreateevent will be emitted when the value for a keypath is deleted (set toundefined) and the reset to a value
Note: a matchingupdateevent will also be emitted for eachcreateevent -
update(< object >updated)
Emitted when a value (or a set of values) is changed for a keypath (or a set of keypaths).
updatedis an object with the updated keypaths as keys and corresponding values as values
Note: anupdateevent will be emitted even if there is no previous value for the keypath -
delete(< object >deleted)
Emitted when a value (or a set of values) is deleted (or set toundefined) for a keypath (or a set of keypaths).
deletedis an object with the deleted keypaths as keys and corresponding values as values
Note: a matchingupdateevent will also be emitted for eachdeleteevent