- Observable value
- Reactive value mutation
- Optionally Immutable
- Optionally Persistent
These Units help you share data among different parts of an app with minimum code and effort. Furthermore, ActiveJS helps in streamlining asynchronous data APIs like
fetch, or third party abstractions like Angular's
npm i @activejs/core
// initialize a reactive data structure to store numbers
const counter = new NumUnit() // with default initial-value 0
// two pure functions to produce an appropriate new value
const increment = value => value + 1
const decrement = value => value - 1
// subscribe for reactive value access, and log the value
counter.subscribe(value => console.log(value))
// immediately logs 0, and will log any future values
counter.dispatch(increment); // you'll see 1 in the console
// the pure function is called with the current value and
// the returned value is dispatched automatically
counter.dispatch(decrement); // you'll see 0 in the console
// that's it our counter is complete
// you can also access the value directly
console.log(counter.value()) // logs 0
Redux vs ActiveJS
It's hard to Compare with NgRx without involving Angular, but for argument's sake let's pretend that this stripped-down code is valid.
NgRx vs ActiveJS
The following data-flow diagram roughly shows where ActiveJS comes into play. ActiveJS holds the state and every other part of the application directly shares it without any obscure façade.
A very high level data-flow diagram of an App using ActiveJS.
ActiveJS is really small in size, and it's tree-shakeable too. Also, there're no reducers, no middleware, and not even a store for that matter. It's much simpler than that.