Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Support observer keys with colons #19436

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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