Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://rawgit.com/Yomguithereal/baobab/master/build/baobab.min.js"></script>
</head>
<body>
</body>
</html>
 
var node = Baobab.dynamicNode;
var identity = function (x) { return x; };
var tree = new Baobab({
  one: {
    foo: node(['one', 'bar'], identity),
    bar: 23
  },
  two: {
    foo: node(['one', 'foo'], identity),
    bar: 23
  },
  three: node(['two'], function(x) {           
    console.log('this should fire'); 
    return x;
  })
});
var watcher = tree.watch({
  finally: ['three']
});
watcher.on('update', function (x) {
  console.log('watcher was called');
});
// Works, watcher is called
tree.select('two', 'bar').set(25);
// Doesn't work!
tree.select('one', 'bar').set(25);
console.log('Watcher should be called twice');
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers