Home Reference Source
import ReactiveBond from './packages/oo7/src/reactiveBond.js'
public class | source

ReactiveBond

Extends:

Bond → ReactiveBond

Constructor Summary

Public Constructor
public

constructor(args: array, dependencies: array, execute: function, mayBeNull: boolean, resolveDepth: number)

Constructs a new object.

Member Summary

Private Members
private
private

_args: *

private
private
private
private
private

Method Summary

Public Methods
public
public
Private Methods
private

Inherited Summary

From class Bond
public static

all(list: array, resolveDepth: number): *

Create a new Bond which represents the array of many objects' representative values.

This object will be ready if and only if all objects in list are themselves ready.

public static

instanceOf(b: *): *

Duck-typed alternative to instanceof Bond, when multiple instantiations of Bond may be available.

public static

mapAll(list: array, f: function, resolveDepth: number, outResolveDepth: number): *

Create a new Bond which represents a functional transformation of many objects' representative values.

public static

promise(list: array): Promise

Create a Promise which represents one or more Bonds.

private static

_fromSymbol(name: *): *

private static

_knowSymbol(name: *): *

private
private
private
private

_notifies: {}

private

_parse: *

private
private
private
private
private

_thens: *[]

private
private
private

_uuid: *

private

_value: *

public

changed(v: *)

Makes the object ready and sets its current value.

public

default(defaultValue: Symbol): *

Provide a Bond which represents the same as this object except that it takes a particular value when this would be unready.

public

defaultTo(x: *): *

Alters this object so that it is always ready.

public

done(f: Bond~thenCallback): *

Register a function to be called when this object becomes done.

public

drop()

Unregister a single dependency for this object.

public

Determine if there is a definite value that this object represents at present.

public

latched(defaultValue: Symbol): *

Provide a derivative Bond which represents the same as this object except that before it is ready it evaluates to a given default value and after it becomes ready for the first time it stays fixed to that value indefinitely.

public

log(): *

Logs the current value to the console.

public

map(transform: function, outResolveDepth: number, cache: *, latched: *, mayBeNull: *): *

Make a new Bond which is the functional transformation of this object.

public

mapEach(transform: function): *

Create a new Bond which represents this object's array value with its elements transformed by a function.

public

Maps the represented value to a string.

public

notReady(): *

Convenience function for the logical negation of Bond#ready.

public

notify(f: Bond~notifyCallback): Symbol

Register a function to be called when the value or the readiness changes.

public

ready(): *

Provide a Bond which represents whether this object itself represents a particular value.

public

reduce(accum: function, init: *): Bond

Lazily transforms the contents of this object's value when it is an array.

This operates on a Bond which should represent an array. It transforms this into a value based on a number of elements at the beginning of that array using a recursive reduce algorithm.

The reduce algorithm works around an accumulator model. It begins with the init value, and incremenetally accumulates elements from the array by changing its value to one returned from the accum function, when passed the current accumulator and the next value from the array. The accum function may return a Bond, in which case it will be resolved (using Bond#then) and that value used.

The accum function returns a value (or a Bond which resolves to a value) of an array with exactly two elements; the first is the new value for the accumulator. The second is a boolean early exit flag.

Accumulation will continue until either there are no more elements in the array to be processed, or until the early exit flag is true, which ever happens first.

public

reset()

Resets the state of this Bond into being not ready.

public

sub(name: string | number, outResolveDepth: number): *

Create a new Bond which represents this object's value when subscripted.

public

Provides a transparently subscriptable version of this object.

public

then(f: Bond~thenCallback): *

Register a function to be called when this object becomes ready.

public

tie(f: Bond~tieCallback): Symbol

Register a function to be called when the value changes.

public

toString(): *

public

trigger(v: *)

Makes the object ready and sets its current value.

public

Unregister a function previously registered with Bond#notify.

public

untie(id: Symbol)

Unregister a function previously registered with Bond#tie.

public

use(): *

Register a single dependency for this object.

public

xform(transform: function, outResolveDepth: number, cache: *, latched: *, mayBeNull: *): *

Just like map, except that it defaults to no latching and mayBeNull.

protected

Uninitialise the object.

protected

Initialise the object.

protected

Returns whether the object is currently in a terminal state.

Public Constructors

public constructor(args: array, dependencies: array, execute: function, mayBeNull: boolean, resolveDepth: number) source

Constructs a new object.

Override:

Bond#constructor

Params:

NameTypeAttributeDescription
args array

Each item that this object's representative value is dependent upon, and which needs to be used by the callback function (presumably to determine that value to be passed into Bond#changed).

dependencies array

Bonds or {Promise}s that the representative value is dependent on, but which are not needed for passing into the callback.

execute function

The callback function which is called when any item of args or deps changes its underlying value. A value corresponding to each item in args are passed to the callback: items that are Bonds are resolved to the value they represent before being passed into the callback execute function. {Promise} objects are likewise resolved for their underlying value. Structures such as arrays and objects are traversed recursively and likewise interpreted. Other types are passed straight through. The callback is only made when all items of args are considered ready.

mayBeNull boolean

Noramlly, null is a valid value for dependent Bonds and Promises to represent. Pass false here to disallow null to be considered valid (and thus any null dependencies in args will mean that dependency is considered not ready and no callback will happen).

resolveDepth number

The maximum number of times to recurse into arrays or objects of args items in searching for Bonds or {Promise}s to resolve.

Private Members

private _active: boolean source

private _args: * source

private _dependencies: * source

private _execute: * source

private _executeReset: * source

private _notifyKeys: *[] source

private _resolveDepth: * source

Public Methods

public finalise() source

Uninitialise the object.

Will be called at most once after an accompanying Bond#initialise and should close/finalise/drop any resources that are required for the sub-class to maintain its value.

Override:

Bond#finalise

public initialise() source

Initialise the object.

Will be called at most once before an accompanying Bond#finalise and should initialise/open/create any resources that are required for the sub-class to maintain its value.

Override:

Bond#initialise

Private Methods

private _notified() source