Ortum
Ortum is a small framework agnostic, unidirectional state
management library.
It's inspired by the work of André Staltz' on Profunctor State Optics
Ortum allows your features to be independent from the global state while having
the ability to use the global state.
By using this, your features are decoupled from their environment, thus easy to test.
Getting started
Install into your project:
$ npm install --save ortum
Give it a try at: https://stackblitz.com/edit/ortum-counter?file=src/counter.ts
Usage in Javascript
Create an initial state, and use it to create the Profunctor.
The useProfunctor
returns an array with two elements:
- the profunctor: basically a store that holds the state and allows access and update it
using the functionsgetState
,setState
andpromap
. - an onStateChange that you can pass a callback of
(state) => console.log(state)
const SimpleStateContainer useProfunctor = ; const initialState = counter: 0 authors: 1: name: 'Andre Staltz' github: 'staltz' 2: name: 'Albert Groothedde' github: 'alber70g' ; // Create the app profunctorconst appProf onStateChange = ; // Listen to state changes; // Use the profunctor to get and set the stateconsole; // `{ counter: 0, authors: { .. } }` // Set state using an Updater: prevState => newState// After this statement you'll get a console.log with // // { counter: 1, authors: { .. } }appProf; // To create a substate profunctorconst authorsProf = appProf console; // { // counter: 1,// 1: {// name: 'Andre Staltz',// github: 'staltz'// },// 2: {// name: 'Albert Groothedde',// github: 'alber70g',// }// }