npm install atom-js
To run from command line using node.js:
node test.js // brief node test.js -v // verbose
To run in a browser, open
test.html, or go
a is an atom.
var a = ;
An atom has properties. The
.set() methods may be employed to
read and write values of any type.
Parameters to the constructor will also be set as properties.
a = ;a = ;
.has() to query for existence of a property, and
.keys() to get a list
of all properties that have been set.
.each() method lets you execute a function on a series of properties.
Listeners may be attached to atoms in a variety of ways.
To be notified as soon as a property is set, use the
.once() method. The
callback will be called immediately if the property is already set.
Many atom methods can work with more than one property at a time.
When you just want to know about the next change, even if the property is
already set, use
To watch for any future changes to a property, use the
Note that setting a property with a primitive (string/number/boolean) value will only trigger listeners if the value is different. On the other hand, setting an array or object value will always trigger listeners.
You can unregister any listener using
If you only want to remove the listener associated with a particular key or keys, you can specify those too:
You can register a provider for a property.
Providers only get invoked if there is a need, and if the property is not
already set. Use the
.need() method to declare a need for a particular
property. If a corresponding provider is registered, it will be invoked.
.need() behaves just like
Properties of two or more atoms can be entangled, using the
method. When an entangled property gets set on one atom, the value will
instantly propagate to the other.
var b = ;a;a;console;
.entangle() also works when called with a list of properties.
If called with a map of property names, then property 'X' on one atom can be entangled with property 'Y' on the other atom.
Note that entangled properties are not actually synchronized until the first change after entanglement.
String together a series of asynchronous functions using the
Not to be confused with the
.chain() method specifically, "method chaining"
actually refers to the practice of stringing together multiple method calls in
a single expression.
.set() methods are all
Release references to all data and callback functions with the