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

var tree = new Baobab({
  user: {
    name: 'Bob',
    settings: {
      foo: 'bar'
    }
  }
});

tree.select('user').merge({ age: 30, likes: 'apples'});

// On update event
tree.select('user').get();
>>> { name: 'Bob', age: 30, likes: 'apples', settings: { foo: 'bar' } }

Note! The merge method will only do a shallow merge.

var Baobab = require('baobab');

var tree = new Baobab({
  user: {
    name: 'Bob',
    settings: {
      foo: 'bar'
    }
  }
});

tree.select('user').merge({ age: 30, settings: {show: 'something'}});

// On update event. Will override the complete settings object, not merge:
tree.select('user', 'settings').get(); 
>>> {show: 'something'}