Skip to content

Commit

Permalink
[BUGFIX lts] Ensure inheritable observers on object proxies are strin…
Browse files Browse the repository at this point in the history
…g based

Fixes #17964
  • Loading branch information
Chris Garrett committed Apr 25, 2019
1 parent fa7444e commit a282444
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
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();
}
}
);

0 comments on commit a282444

Please sign in to comment.