npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

neden

v0.0.4

Published

Empirical Modelling for node.js

Downloads

2

Readme

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 = 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:

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:

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.

var s = eden((x, y) => x + y, a, c);

Note that you could also do the same assuming with an unbounded argument list:

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:

s();
# 9

Redefine a dependency

Call the associated function with a replacement function and dependencies:

s(x => x - 1, a);
s();
# 1

To break all dependencies, change s into an observable, perhaps setting the value to null:

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:

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. For example:

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.