This package has been deprecated

Author message:

WARNING: This project has been renamed to entangld. Install using entangld instead.

synchronized-entity-store

1.0.0 • Public • Published

Synchronized Entity Store (SES)

object-safe, easily synchronizable entity store with request events. Works over sockets (try it with Sockhop!)

Example

	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

Raison d'etre

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?

Ses ⇐ EventEmitter

Synchronized Event Store

Kind: global class
Extends: EventEmitter

ses.namespaces ⇒ array

Get namespaces

Kind: instance property of Ses
Returns: array - namespaces an array of attached namespaces
Read only: true

ses.namespace() ⇒ string

Get namespace for a store

Kind: instance method of Ses
Returns: string - namespace for the given store
Read only: true

ses.attach(namespace, store)

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

ses.detach([namespace], [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

ses.transmit(f)

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

ses.receive(msg, [store])

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

ses.set(path, the)

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

ses.get(path) ⇒ object

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")

ses.subscribe(path, f)

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)

TODO

  • Make sure incoming values request store doesn't build up

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i synchronized-entity-store

Weekly Downloads

1

Version

1.0.0

License

SEE LICENSE IN README.md

Last publish

Collaborators

  • c0d3runn3r