Changing state in the tree - Yomguithereal/baobab GitHub Wiki

You have several ways of changing the state in your tree. Most of them are traditional API methods like push and unshift for arrays, but you also have other methods, as shown below.

var Baobab = require('baobab');
var ajax = require('ajax'); // Some ajax lib

var tree = new Baobab({
  todos: [],
  isLoading: false
});

// Grabbing existing todos from server
tree.set('isLoading', true);
fetch('/todos', function (todos) {
  tree.select('todos').edit(todos);
  tree.set('isLoading', false);
});

// Adding a new todo
tree.select('todos').unshift({title: 'foo'});