Skip to content
Christian Alfoni edited this page Mar 13, 2015 · 3 revisions
var Baobab = require('baobab');

var tree = new Baobab({
  todos: {
    items: [],
    isLoading: false,
  },
  user: {
    name: 'Bob'
  }
});

tree.select('todos', 'items').apply(function (items) {
  return items.concat({title: 'foo'});
});

tree.select('todos', 'isLoading').apply(function (isLoading) {
  return !isLoading;
});

tree.select('user').apply(function (user) {
  user.age = 32;
  return user;
});

// On update event
tree.select('todos', 'items').get();
>>> [{title: 'foo'}]

tree.select('todos', 'isLoading').get();
>>> true

tree.select('user').get();
>>> { name: 'Bob', age: 32 }