Skip to content

Listening to changes

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

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

var todos = tree.select('todos');

// We create a cursor on the first item in the array,
// which will be the latest todo added
var latestTodo = tree.select('todos', 0);

// We listen to any changes in the todos array, it
// being the array itself or something inside the array
todos.on('update', function () {
  // I always trigger
});

// We listen to any changes on the first todo in the,
// array
latestTodo.on('update', function () {
  // I only trigger when first item in array changes
});