Skip to content

Commit

Permalink
Merge pull request #19436 from bertdeblock/fix/observer-keys-with-colons
Browse files Browse the repository at this point in the history
[BUGFIX beta] Support observer keys with colons
  • Loading branch information
rwjblue authored Mar 8, 2021
2 parents a77343f + 09b767d commit 81fac42
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 81fac42

Please sign in to comment.