Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomguithereal committed Dec 14, 2015
1 parent f1867a3 commit e11aeda
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build/baobab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,9 @@ var Watcher = (function (_Emitter) {

return rawPaths.reduce(function (cp, p) {

// Handling path polymorphisms
p = [].concat(p);

// Dynamic path?
if (_type2['default'].dynamicPath(p)) p = _helpers.getIn(_this2.tree._data, p).solvedPath;

Expand Down
4 changes: 2 additions & 2 deletions build/baobab.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export default class Watcher extends Emitter {

return rawPaths.reduce((cp, p) => {

// Handling path polymorphisms
p = [].concat(p);

// Dynamic path?
if (type.dynamicPath(p))
p = getIn(this.tree._data, p).solvedPath;
Expand Down
15 changes: 15 additions & 0 deletions test/suites/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ describe('Watchers', function() {
assert.strictEqual(count, 2);
});

it('should be possible to pass paths following usual polymorphisms.', function() {
const tree = new Baobab({name: 'John', surname: 'Talbot'}, {asynchronous: false});

const watcher = tree.watch({
name: 'name',
surname: 'surname'
});

assert.deepEqual(watcher.get(), {name: 'John', surname: 'Talbot'});

tree.set('name', 'Jack');

assert.deepEqual(watcher.get(), {name: 'Jack', surname: 'Talbot'});
});

it('should be possible to use dynamic paths.', function() {
const tree = new Baobab({
data: [{id: 0, txt: 'Hello'}, {id: 1, txt: 'World'}]
Expand Down

0 comments on commit e11aeda

Please sign in to comment.