object-safe, easily synchronizable entity store with request events. Works over sockets (try it with Sockhop!)
var parent=new Ses();
var child=new Ses();
// Attach child namespace
s.attach("child",child);
// Configure communications
parent.transmit((msg, store)=>store.receive(msg)); // store === child in this example
child.transmit((msg)=>parent.receive(msg, child));
// Set something in the child...
child.set("system.voltage",33);
// Get it back in the parent
parent.get("child.system.voltage"); // == 33
Any object can store values. And a Map can store values keyed to objects. But what if you want to....
- Have your store synchronized with multiple data sources (other stores)?
- Over a network?
- Subscribe to events within the datastore?
Synchronized Event Store
Kind: global class
Extends: EventEmitter
-
Ses ⇐
EventEmitter
Get namespaces
Kind: instance property of Ses
Returns: array
- namespaces an array of attached namespaces
Read only: true
Get namespace for a store
Kind: instance method of Ses
Returns: string
- namespace for the given store
Read only: true
Attach a namespace and a store
Kind: instance method of Ses
Throws:
-
Error
Error will be thrown if you try to attach a namespace twice
Param | Type | Description |
---|---|---|
namespace | string |
a namespace for this store |
store | object |
an object that will be sent along with "transmit" callbacks when we need something from this store |
Detach a namespace / store pair
If you only pass a namespace or a store, it will find the missing item before detaching
Kind: instance method of Ses
Throws:
-
Error
Error will be thrown if you don't pass at least one parameter
Param | Type | Description |
---|---|---|
[namespace] | string |
the namespace |
[store] | object |
the store |
Transmit
Specify a callback to be used so we can transmit data to another store Callback will be passed (msg, store) where msg is an object and store is the Ses store that should receive() it
Kind: instance method of Ses
Param | Type | Description |
---|---|---|
f | function |
the callback function |
Receive
Call this function with the data that was sent via the transmit() callback
Kind: instance method of Ses
Param | Type | Description |
---|---|---|
msg | object |
the message that was given to the callback |
[store] | object |
the Ses store that sent the message |
Set an object into the store
Kind: instance method of Ses
Throws:
-
Error
Throws error on empty path
Param | Type | Description |
---|---|---|
path | string |
the path to set (like "system.fan.voltage") |
the | object |
object you want to set it to |
Get an object from the store
Kind: instance method of Ses
Returns: object
- the object living at that path
Throws:
-
Errror
throws error on empty path
Param | Type | Description |
---|---|---|
path | string |
the path to query (like "system.voltage") |
Subscribe to change events for a path
If objects at or below this path change, you will get a callback
Kind: instance method of Ses
Throws:
-
Error
error thrown on empty path
Param | Type | Description |
---|---|---|
path | string |
the path to watch |
f | function |
the callback - will be of the form (path, value) |
- Make sure incoming values request store doesn't build up
MIT