@thi.ng/atom
About
Clojure inspired mutable wrappers for (usually) immutable values, with support for watches.
TODO
Installation
yarn add @thi.ng/atom
Usage examples
Atom
import * as atom from "@thi.ng/atom";
const a = new atom.Atom(23);
a.deref();
a.addWatch("foo", (id, prev, curr) => console.log(`${id}: ${prev} -> ${curr}`));
a.swap((val)=> val + 1);
a.reset(42);
Cursor
main = new atom.Atom({a: 23, b: 42});
cursor = new atom.Cursor(main, (state) => state.a, (state, x) => ({...state, a: x}));
cursor.addWatch("foo", console.log);
cursor.deref()
cursor.swap(x => x + 1);
main.deref()
Authors
License
© 2018 Karsten Schmidt // Apache Software License 2.0