# neden

> Empirical Modelling for node.js

Latest version **0.0.4** (published 2017-07-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install neden
pnpm add neden
yarn add neden
bun add neden
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2017-07-16 |
| First published | 2017-07-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Streampunk Media |
| Maintainers | streampunk |
| Keywords | Empirical, Modelling, Construal |

## Links

- npm: https://www.npmjs.com/package/neden
- Repository: https://github.com/Streampunk/neden
- Homepage: https://github.com/Streampunk/neden#readme
- Issues: https://github.com/Streampunk/neden/issues
- npm.io page: https://npm.io/package/neden

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^3.1.0

## Recent versions

- 0.0.4 (latest) — 2017-07-16
- 0.0.3 — 2017-07-16
- 0.0.2 — 2017-07-15
- 0.0.1 — 2017-07-15

## README

# Neden

Bare bones [Empirical Modelling](https://en.wikipedia.org/wiki/Empirical_modelling) support for [Node.JS](https://nodejs.org/en/), 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:

```javascript
var a = eden(1);
var b = eden(true);
var c = eden('hello');
var d = eden([1, 2, 3]);
```

Each declaration returns a function.

### Read values

To read the values of observables, call the associated function with no arguments:

```javascript
a();
# 1
b();
# true
c();
# 'hello'
d();
# [1, 2, 3]
```

### Change observables

To change the value of an observable, call the association function with a
single argument containing the replacement value:

```javascript
a(2);
# 2
b(false);
# false
c(7);
# 7 - note that the observable changes type
d({ key: 'value'});
# { 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.

```javascript
var s = eden((x, y) => x + y, a, c);
```

Note that you could also do the same assuming with an unbounded argument list:

```javascript
var t = eden((...x) => x.reduce((y, z) => y + z), a, c);
```

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:

```javascript
s();
# 9
```

### Redefine a dependency

Call the associated function with a replacement function and dependencies:

```javascript
s(x => x - 1, a);
s();
# 1
```

To break all dependencies, change `s` into an observable, perhaps setting the value to `null`:

```javascript
s(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:

```javascript
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] }

s.f.toString();
# 'x => x - 1'
```

### Asynchronous behaviour

Neden can be used with Node.JS [promises](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise). For example:

```javascript
var tp = (v, t) => new Promise((f, r) => { setTimeout(() => f(v), t); });
var ta = (...x) => Promise.all(x).then(y => y.reduce((x, y) => x + y));
var a = eden(tp(7, 3000));
var b = eden(tp(42, 8000));
var c = eden(ta, a, b);
c();
# Promise { <pending> }

# Wait 8 seconds
c();
# Promise { 49 }
```

## Status and next steps

This is an experimental prototype for research purposes only with no commitment to further development.

---
_Source: https://npm.io/package/neden · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
