factjs

1.0.0 • Public • Published

Fact.js - Flexible and correctness-prone process composition, now in Javascript!

Fact.js is a code orchestration library that makes it easier to write maintainable Javascript. It is a straightforward port of the Factfold Clojure library.

How does it work

From the Factfold README:

Factfold processes data by applying models to facts† in chronological order. Models associate property names with functions to compute their values. Grouping model properties into orders makes their logical dependencies clear to human readers, and provides a natural concurrency barrier. Each property's value is computed from a snapshot of the current state and a new datum. † Feel free to substitute "applying models to facts" with "calculating views of documents", "dispatching messages to actors/objects/processes", "executing instructions on a thread", "handling events in a queue", "updating relations with records", etc.

In the reference implementation, the state object (like most Clojure data structures) employs structural sharing, allowing cheap immutable copies while code performs "mutations" and the runtime stores only the differences. This implementation does not make any such affordances, though of course if you like immutability there are libraries like mori (which implements ClojureScript's persistent data structures) and Immutable.js.

Usage

Fact.js exports a single function, evaluate. This function takes the model, the current model state, and the new datum as input.

const helloModel = [
  {greeting: (s, f) => (f.subject ? `Hello, ${f.subject}!` : s.greeting)},
];

JSON.stringify(evaluate(helloModel, {}, {subject: 'world'})) == '{"greeting":"Hello, world!"}'

License

Licensed under the Eclipse Public License version 1.0.

Copyright Duncan Smith 2017

Readme

Keywords

none

Package Sidebar

Install

npm i factjs

Weekly Downloads

0

Version

1.0.0

License

Eclipse Public License

Last publish

Collaborators

  • notduncansmith