Skip to content

Commit

Permalink
[BUGFIX beta] Support observer keys with colons
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Feb 28, 2021
1 parent 8c85b2b commit 09b767d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function activateObserver(target: object, eventName: string, sync = false
if (activeObservers.has(eventName)) {
activeObservers.get(eventName)!.count++;
} else {
let [path] = eventName.split(':');
let path = eventName.substring(0, eventName.lastIndexOf(':'));
let tag = getChainTagsForKey(target, path, tagMetaFor(target), peekMeta(target));

activeObservers.set(eventName, {
Expand Down
15 changes: 15 additions & 0 deletions packages/@ember/-internals/metal/tests/observer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ moduleFor(
assert.equal(count, 1, 'should have invoked observer');
}

async ['@test observer supports keys with colons'](assert) {
obj = {};
let count = 0;

addObserver(obj, 'foo:bar:baz', function () {
assert.equal(get(obj, 'foo:bar:baz'), 'bar', 'should invoke AFTER value changed');
count++;
});

set(obj, 'foo:bar:baz', 'bar');
await runLoopSettled();

assert.equal(count, 1, 'should have invoked observer');
}

async ['@test observer should fire when dependent property is modified'](assert) {
obj = { bar: 'bar' };
defineProperty(
Expand Down

0 comments on commit 09b767d

Please sign in to comment.