Treeful
It's a(nother) state manager! But let's not get overwhelmed. Treeful simply provides the following to your app.
- Single global object contains all states.
- Subset of the states can be subscribed with callback functions.
- States can be updated.
That's it. No steep learning curve, no configuration. And regardless of its simplicity, Treeful has distinct characteristics that makes it powerful.
- Less code - Minimal lines of code are sufficient. No extra files needed.
- Tree structure - Your state can be nested, and subscribing to parent will automatically subscribe to its children.
- Efficient data transfer - You won't pass around whole tree. Only the subscribed set will be passed for efficiency.
- Framework independent - No wrappers needed. Keep your code as is.
Install
npm install treeful
Basic Usage
First, import the package and create your tree (you don't need to instantiate)
;Treeful // Add node 'count' with value 0 (to 'root') // Add node 'todos' to 'root' ; // Add node 'filter' to 'todos' with value of 'all'
Our tree now looks like this:
Subscribe to node 'todos'
by calling:
Treeful;// callbackTodos will get called when the data in 'todos' or 'filter' gets updated
Get and set data by calling:
let oldData = Treeful; // oldData = 'all'Treeful;// Node 'filter' is updated, and it is a child of 'todos' that is subscribed to callbackTodos
callbackTodos is now called, and passed the new data
{ // data = 'completed' (updated data) // node = 'filter' (node that changed) // do some stuff}
Documentation
APIs and examples - please refer to documentation.
Contribute
Join the party - please refer to contributing.
License
MIT - please refer to license.