Neden
Bare bones Empirical Modelling support for Node.JS, allowing any Javascript value to be established as an observable and Javascript functions to be used to establish a dependency.
Installation
To use neden, add it to your package using npm in the normal way:
npm install --save neden
The package has one function that you require in your code:
var eden = require('neden');
This code is intended to be used in the Node.JS REPL for interactive and iterative experimentation.
Usage
Declare observables
Declare observables as follows:
var a = ;var b = ;var c = ;var d = ;
Each declaration returns a function.
Read values
To read the values of observables, call the associated function with no arguments:
;# 1;# true;# 'hello';# 1 2 3
Change observables
To change the value of an observable, call the association function with a single argument containing the replacement value:
;# 2;# false;# 7 - note that the observable changes type;# key : 'value' - also changes type
Do not declare the variables again as this will orphan the observable and not trigger any changes of dependent values.
Create a dependency
Create a new dependency using a function and the observables that it depends upon.
var s = ;
Note that you could also do the same assuming with an unbounded argument list:
var t = ;
In both cases, the value returned is a function.
Read the value of an evaluated dependency
To read the value of an evaluated dependency, call the associated function with no arguments:
;# 9
Redefine a dependency
Call the associated function with a replacement function and dependencies:
;;# 1
To break all dependencies, change s
into an observable, perhaps setting the value to null
:
;
Inspect the dependency tree
Observables and definitions have a property called deps
which is an object containing a map from the unique internal identifier of any value that depends on this value and the function to call to update the dependent value.
Definitions have a value called dpnd
which is an array of all the observables that are depended on. They also have a value called f
which is the function to call to update the values.
These values can be inspected in the REPL by typing the function name without calling the function, for example:
a;# Function: ob# deps: '0fdacd4d-9257-42c1-889d-a631507d3172': Function: fn # dpnd: # f: undefined s;# Function: ob# deps: {}# dpnd: Function: ob deps: Object dpnd: fn: undefined # f: Function sf;# 'x => x - 1'
Asynchronous behaviour
Neden can be used with Node.JS promises. For example:
var { ; };var Promiseallx;var a = ;var b = ;var c = ;;# Promise <pending> # Wait 8 seconds;# Promise 49
Status and next steps
This is an experimental prototype for research purposes only with no commitment to further development.