Socket
Socket
Sign inDemoInstall

treeful

Package Overview
Dependencies
0
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    treeful

Let's not get overwhelmed. It's just a state manager.


Version published
Maintainers
1
Install size
14.5 kB
Created

Readme

Source

Treeful

npm version build status coverage status

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 node 'count' with value 0 (to 'root')
    .add('todos', [], 'root')       // Add node 'todos' to 'root'
    .add('filter', 'all', 'todos'); // Add node 'filter' to 'todos' with value of 'all'

Our tree now looks like this:

Tree

Subscribe to node 'todos' by calling:

Treeful.subscribe('todos', callbackTodos);
// callbackTodos will get called when the data in 'todos' or 'filter' gets updated

Get and set data by calling:

let oldData = Treeful.get('filter'); // oldData = 'all'
Treeful.set('filter', 'completed');
// 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

function callbackTodos(data, node) {
    // 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.

Keywords

FAQs

Last updated on 09 Aug 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc