Skip to content

Commit

Permalink
Fix observing escaped keypaths (#3319)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilessiivi authored and evs-chris committed Nov 1, 2019
1 parent c071da6 commit f0f90e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/model/ModelBase.js
Expand Up @@ -82,7 +82,7 @@ export default class ModelBase {
children.push(this.joinKey(i));
});
} else if (isObject(value) || isFunction(value)) {
children = objectKeys(value).map(key => this.joinKey(key));
children = objectKeys(value).map(key => this.joinKey(escapeKey(key)));
} else if (value != null) {
children = [];
}
Expand Down
20 changes: 20 additions & 0 deletions tests/browser/methods/observe.js
Expand Up @@ -621,6 +621,26 @@ export default function() {
ractive.set('gup.foo.bar', { baz: 2 });
});

test('An observed wildcard can be an escaped string (#3319)', t => {
t.expect(4);

const ractive = new Ractive({
el: fixture,
template: 'blah',
data: { gup: { 'foo.bar': { baz: 1 } } }
});

let expected = 1;

ractive.observe('gup.*.baz', (n, o, keypath) => {
t.deepEqual(n, expected);
t.equal(keypath, 'gup.foo\\.bar.baz');
});

expected = 2;
ractive.set('gup.foo\\.bar', { baz: 2 });
});

test('Pattern observers fire when ractive.update() is called without parameters', t => {
t.expect(2);

Expand Down

0 comments on commit f0f90e7

Please sign in to comment.