Keymit (ALPHA)
What is it?
Keymit is an object store that allows you to subscribe to changes at any depth of the object store. You can subscribe to all changes in the store, changes to only certain branches, or subscribe to only when a single value changes.
Usage
Creating a keymit object
const Keymit = ; let keymit = ;
Settings keys values
// Set/update values in the keysore with an objectkeymit; // Alternatively, you can set/update values with flat keys// (default delimiter is a '.')keymit; // If your keys values have been serialized from another language (such as C#),// you can simply pass those tookeymit;
Gettings key values
// Get a copy of all valueslet all = keymit; // Get a copy of only specific pathlet ontario = keymit;
Subscribing
{ console;} // Subscribe to all recordskeymit; // Subscribe to only a portion of the recordskeymit; // Subsribe to only a single recordkeymit;
Unsubscribing
{ console;} // Unsubscribe to all recordskeymit; // Unsubscribe to only a portion of the recordskeymit; // Unsubscribe to only a single recordkeymit;
Documentation
Methods
- ()
- Creates a new keymit instance.
- Parameters
String
: optional delimiter for all keys [default is '.']
- Delete
- Deletes a branch or value from the store.
- Parameters
String
: optional delimited path to delete [defaults to deleting all records]
- set
- Sets a branch or value in the store.
- Parameters
String
orObject
: The key string or object of key values*
: value to use if previous parameter was a string
- get
- Gets a branch or value from the store.
- Parameters
String
: optional delimited path to filter by
- subscribe
- Adds a subscription.
- Parameters
String
: optional delimited path to subscribe to [defaults to all records]Function
: callback to run on changeObject
: optional optionsBoolean
: flatten flatten the records with the delimiter before passing them back [default is false]Boolean
: triggerNow have the callback immediately execute with the current value [defaults is false]Boolean
: lean have only changes sent (excluding the initial triggerNow) [default is false]
- unsubscribe
- Remove a subscription.
- Parameters
String
: optional delimited path to unsubscribe to [defaults to all records]Function
: callback to unsubscribe
- unsubscribeAll
- Removes all subscriptions.
Properties
listenerCount
(Number): Number of active subscriptions
Tests
Install npm mocha
either local or globally and run mocha tests
.