2.0.1 • Published 9 years ago

treeful v2.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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.

2.0.1

9 years ago

2.0.0

9 years ago

1.7.4

9 years ago

1.7.3

9 years ago

1.7.2

9 years ago

1.7.1

9 years ago

1.7.0

9 years ago

1.6.12

9 years ago

1.6.11

9 years ago

1.6.10

9 years ago

1.6.9

9 years ago

1.6.8

9 years ago

1.6.7

9 years ago

1.6.6

9 years ago

1.6.5

9 years ago

1.6.4

9 years ago

1.6.3

9 years ago

1.6.2

9 years ago

1.6.1

9 years ago

1.6.0

9 years ago

1.5.0

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.3.1

9 years ago

1.2.1

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.0

9 years ago