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 lts] Ensure inheritable observers on object proxies are string based #17974

Merged
merged 1 commit into from
Apr 25, 2019
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
20 changes: 10 additions & 10 deletions packages/@ember/-internals/runtime/lib/mixins/-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ import {
import { setProxy } from '@ember/-internals/utils';
import { assert } from '@ember/debug';

function contentPropertyDidChange(content, contentKey) {
let key = contentKey.slice(8); // remove "content."
if (key in this) {
return;
} // if shadowed in proxy
notifyPropertyChange(this, key);
}

export function contentFor(proxy, m) {
let content = get(proxy, 'content');
let tag = (m === undefined ? meta(proxy) : m).readableTag();
Expand Down Expand Up @@ -72,12 +64,20 @@ export default Mixin.create({

willWatchProperty(key) {
let contentKey = `content.${key}`;
addObserver(this, contentKey, null, contentPropertyDidChange);
addObserver(this, contentKey, null, '_contentPropertyDidChange');
},

didUnwatchProperty(key) {
let contentKey = `content.${key}`;
removeObserver(this, contentKey, null, contentPropertyDidChange);
removeObserver(this, contentKey, null, '_contentPropertyDidChange');
},

_contentPropertyDidChange(content, contentKey) {
let key = contentKey.slice(8); // remove "content."
if (key in this) {
return;
} // if shadowed in proxy
notifyPropertyChange(this, key);
},

unknownProperty(key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DEBUG } from '@glimmer/env';
import {
addObserver,
observer,
computed,
get,
set,
Expand Down Expand Up @@ -317,5 +318,15 @@ moduleFor(
'sets the `undefined` value to the proxied content'
);
}

['@test should not throw or deprecate when adding an observer to an ObjectProxy based class'](
assert
) {
assert.expect(0);

ObjectProxy.extend({
observe: observer('foo', function() {}),
}).create();
}
}
);