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

var tree = new Baobab({
  todos: {
    isLoading: false,
    items: [{id: '123', title: 'foo'}]
  }
});

// Select with string
tree.select('todos');

// Select by multiple arguments
tree.select('todos', 'isLoading');

// Select with index
tree.select('todos', 'items', 0);

// Select with object
tree.select('todos', 'items', {id: '123'});

// Select by multiple select
tree.select('todos').select('items');
tree.select('todos').select('items').select(0);

// Select by array
tree.select(['todos']);
tree.select(['todos', 'isLoading']);
tree.select(['todos', 'items', 0]);
tree.select(['todos', 'items', {id: '123'}]);

// Combine
tree.select(['todos'], 'items').select(0);
tree.select(['todos'], 'items').select({id: '123');

// Filter arrays
tree.select('todos', 'items', function (todo) {
  return todo.completed;
});

// You can also point to data that is not set yet,
// but might be later
tree.select('i_will_have_some_data_later');