The simpliest store for managing the state in your application.
Works in all environments and all browsers.
Why do I need a centralized state management?
Managing the information rendered is difficult, mostly when our apps grow large and the state is scattered across many components and the interactions between them without control.
To solve this, the current state of the art solution is to use a globalized state where we can centralize and have more control over the information we have to render. Almy is a simple library that uses a pub/sub façade along with a centralized state management which makes the the side effects of changing information easy to control and eliminates the risk of getting race conditions in our applications.
npm install --save almy
- dispatch(key: string, value: any)
Dispatches some event that happened in a key value fashion
- subscribe(key: string, callback: Function)
Subscribes to dispatched events. If someone has dispatched an event before, it calls the callback right away
Returns the state of your application
Including it as a script tag
Including it as a module
Using in a node environment
const almy =almy//In some other place in your codealmy
You can also dispatch objects:
const almy =almyalmy
Or subscribe to objects properties and receive every change:
almy;...almy...almy// This would ouput:// "Intructions per seconds are 1"// "Intructions per seconds are 5"
Only one object deepness subscriptions are supported. Example:
almy// This doesn't workalmy// This does workalmy
A flatten state is easier to reason and understand.
Other state management libraries
- Vuex: https://github.com/vuejs/vuex
- Redux: https://github.com/reduxjs/redux
- Flux: https://github.com/facebook/flux
Worlds: Controlling the Scope of Side Effects http://www.vpri.org/pdf/tr2011001_final_worlds.pdf