From a28244430f9e7048fc625e02d8478c46f47c30b1 Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Thu, 25 Apr 2019 11:31:30 -0700 Subject: [PATCH] [BUGFIX lts] Ensure inheritable observers on object proxies are string based Fixes #17964 --- .../-internals/runtime/lib/mixins/-proxy.js | 20 +++++++++---------- .../runtime/tests/system/object_proxy_test.js | 11 ++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/@ember/-internals/runtime/lib/mixins/-proxy.js b/packages/@ember/-internals/runtime/lib/mixins/-proxy.js index d145f85fe18..2daa77edab1 100644 --- a/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +++ b/packages/@ember/-internals/runtime/lib/mixins/-proxy.js @@ -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(); @@ -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) { diff --git a/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js b/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js index 0a73fc39a1b..90ac165d0ca 100644 --- a/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js +++ b/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js @@ -1,6 +1,7 @@ import { DEBUG } from '@glimmer/env'; import { addObserver, + observer, computed, get, set, @@ -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(); + } } );