Class: SyncedObject

SyncedObject

This class wraps an object and detects when it is changed from the outside world.

new SyncedObject()

Source:
Example
var synced = new SyncedObject();
synced.on('changed', function (changeset) {
  console.log(changeset.changed); // { 'foo': 'bar' }
});
synced.data.foo = 'bar';

Mixes In

Members

data :Object

The wrapped data object. Changes to it's top level attributes are detected and a changed event is fired in this case.
Type:
  • Object
Source:

Methods

applyChangeset(changeset)

Applies the given changeset to the wrapped object. Note that this method fires a changed event if any attribute does change. If you don't want to receive this event, use applyChangesetSilently instead.
Parameters:
Name Type Description
changeset SyncedObject.Changeset changes that should be applied to the wrapped object
Source:
Fires:

applyChangesetSilently(changeset)

Applies the given changeset to the wrapped object without fireing a changed event.
Parameters:
Name Type Description
changeset SyncedObject.Changeset changes that should be applied to the wrapped object
Source:

get(name, timeout) → {external:Promise}

Get the value of a specific attribute from the synced object. If the value is not present yet, it will be passed to the returned promise later on. This should make handling async code a bit easier.
Parameters:
Name Type Argument Default Description
name string name of the attribute whose value you want to know
timeout integer <optional>
3000 time in milliseconds after which the returned promise will be rejected, if the attribute is not present
Source:
Returns:
On success the promise will be resolved with the value of the requested attribute. Has the attribute not been available after the given timout, the promise will be rejected with a generic error.
Type
external:Promise
Example
var sync = new SyncedObject();
sync.startWatching();
sync.get('foo').then(function (value) {
  console.log(value); // will be 'bar'
});
sync.get('na').fail(function (error) {
  // when 'na' has never been set
  console.log(error);
});
sync.data.foo = 'bar';

startWatching()

Starts detecting changes to the wrapped object.
Source:

Type Definitions

Changeset

Properties:
Name Type Description
changed Object.<string, *> any changed top level attributes: their new value mapped to their name
removed Array.<string> names of all top level attributes that have been deleted
Source:

Events

changed

Fired when any top level attribute of the wrapped object has changed.
Properties:
Name Type Description
changeset SyncedObject.Changeset what has changed exactly?
Source: