The ultimate global variable.
If you'd prefer to dive right in to creating interactive applications with
Horten, see the horten-server module. It provides pretty, easy, realtime controls, persistence,
His created. The property
H.rootcontains a reference to a default global
Mutant. This root is used by default by all new
Horten paths are lists of keys which allow deep access to objects. They may be represented as either an
Array or a
Most methods which accept paths will accept paths as multiple arguments. For instance, the follow calls are all equivalent:
var value =foo:bar:baz: 42var result = Hassert
For various historical and practical reasons, the canonical
String representation of paths is delimited by
'/' with a trailing slash. Deal with it.
Mutants are Horten's method for encapsulating mutable object operations, while maintaining immutability of inputs and outputs. For example:
const initialValue = foo: 'bar' baz: 'bop'mutant = initialValueassertassertmutantassertassert
When Mutants are used to store non-primitive data, they are organized into a static tree structure. Each
Mutant has any number of submutants, keyed by path segments. Submutants will be created automatically, and are never destroyed.
When a submutant is mutated, its parent will be mutated, and vice-versa.
const root =sub = root// `sub` is a submutant of `root` at the path 'foo/'assertassert// Since we didn't specify an initial value for `root`,// the value of `sub` is undefined.assert// We can set the value of `sub` directly, and the// change will propagate to `root`.subassert// If the value of `root` is set, `sub` will be set as well.rootassert
change(): The value of the object has changed.
value( value ): The new value of the object.
delta( delta ): The delta between the object's previous value and its new one.