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)
import Treeful from 'treeful';
Treeful.add('count', 0)
.add('todos', [], 'root')
.add('filter', 'all', 'todos');
Our tree now looks like this:
Subscribe to node 'todos'
by calling:
Treeful.subscribe('todos', callbackTodos);
Get and set data by calling:
let oldData = Treeful.get('filter');
Treeful.set('filter', 'completed');
callbackTodos is now called, and passed the new data
function callbackTodos(data, node) {
}
Documentation
APIs and examples - please refer to documentation.
Contribute
Join the party - please refer to contributing.
License
MIT - please refer to license.