callbag-state
Callbag-based state management.
npm i callbag-state
;; ;subscribeconsole.log'GOT: ' + vs;console.logs.get;s.set43;console.logs.get; // > GOT: 42// > 42// > GOT: 43// > 43
Usage
👉 Track the state and mutate it via .set()
and .get()
:
;; ;subscribeconsole.logs; s.set43;s.sets.get + 1; // > 42// > 43// > 44
👉 Track sub-states:
;; ;;subscribeconsole.logs; x.set43;x.setx.get + 1; // > {x: 42}// > {x: 43}// > {x: 44}
👉 Changes propagate properly wherever you make them on state-tree:
;; ; subscribeconsole.logs.sub0.sub'x'; s.set;s.sub0.set;s.sub0.sub'x'.set45; // > 42// > 43// > 44// > 45
👉 Track changes:
;; ;subscribeconsole.logs.downstream; s.set; // > {// > value: [5, 2, 3, 4, 1],// > trace: {// > subs: {// > 0: { from: 1, to: 5 },// > 4: { from: undefined, to: 1}// > }// > }
Gotchas
⚠️⚠️ Don't change an object without changing its reference:
// WRONG:s.get.push5; // --> no updates
// CORRECT:s.set;
// FUN & CORRECT:s.subs.get.length.set5
⚠️⚠️ Only pass plain objects! Specifically, passing objects with circular references might result in stack-overflow!
Contribution
Be nice and respectful, more importantly super open and welcoming to all.
👉 Useful commands for working on this repo:
git clone https://github.com/loreanvictor/callbag-state.git
npm i # --> install dependencies
npm start # --> run `samples/index.ts`
npm test # --> run all tests
npm run cov:view # --> view code coverage