Stability: 1 - Experimental
Stability as defined by Node.js
A module for creating computed value in reactive programming style.
npm install computed-value
Below example can be also found in examples/fullname.js.
var computedValue = ;var first = ;var last = ;var fullName =;console;first;console;fullName;last;
The output of running the above script will be:
Tom Dale Bob Dale update: Bob Johnson
If no arguments are passed to the function, it simply returns the computed value stream. You can read it's
value (it will be
undefined), and you can
write to it to initialize it.
var computedValue = ;var name = ;console;// -> undefinedname;console;// -> 'Julia'
If a single, non-function argument is passed,
computedValue will initialize the underlying computed value stream with the
initialValue, then return it.
var computedValue = ;var name = ;console;// -> 'Julia'name;console;// -> 'Julie'
If more than one arguments are passed in,
computedValue assumes that the last argument is a function that will take as input the values of each
dependency listed before it, just like in the
Usage example above. Each
dependency must be a computed value itself in order for the mechanism to work correctly. (it will attempt to lookup
value property as well as try to register a listener for an
update event, see index.js for details).
var computedValue = ;var first = ;var last = ;var fullName =;console;// -> 'Tom Anderson'var title = ;var titledFullName =;console;// -> 'Mr. Tom Anderson'first;console;// -> 'Mr. Jake Anderson'