kvcobj

0.1.0-6 • Public • Published

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, an update (and possibly also a create or delete , see below) event will be triggered, unless silent is set to true.

  • getObject() - (object)
    Returns the current root as a normal object.

  • setObjectForKeypath(< object >object, < string >rootKeypath, [< bool >silent]) - (void)
    Sets all values of object, where rootKeypath will be the keypath to the root of the object. If this leads to a change of the object, an update (and possibly also a create or delete, see below) event will be triggered, unless silent is set to true.

  • getObjectForKeypath(< string >keypath) - (object)
    Returns the object from keypath.

  • setValueForKeypath(< non-object >value, < string >keypath, [< bool >silent]) - (void)
    Sets value at keypath. If this leads to a change of the object, an update (and possibly also a create or delete , see below) event will be triggered, unless silent is set to true.

  • getValueForKeypath(< string >keypath) - (non-object)
    Returns the value at keypath.

  • commit() - (void)
    Commits uncommited changes made with silent set to true. 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 new create event will be emitted when the value for a keypath is deleted (set to undefined) and the reset to a value
    Note: a matching update event will also be emitted for each create event

  • update(< 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: an update event 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 to undefined) 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 matching update event will also be emitted for each delete event

Readme

Keywords

none

Package Sidebar

Install

npm i kvcobj

Weekly Downloads

0

Version

0.1.0-6

License

none

Last publish

Collaborators

  • martinvl