Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

factjs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

factjs

Flexible and correctness-prone process composition, now in Javascript

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 19 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts