From a1ee4abf873063b994440ec5bc43b17a87b683bf Mon Sep 17 00:00:00 2001 From: bekzod Date: Sun, 9 Jul 2017 19:50:18 +0500 Subject: [PATCH 1/2] enable templates read a property from a function --- .../tests/integration/content-test.js | 16 ++++++++-------- packages/ember-metal/lib/property_set.js | 1 - packages/ember-metal/lib/tags.js | 2 +- packages/ember-metal/lib/watch_key.js | 7 +++---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/ember-glimmer/tests/integration/content-test.js b/packages/ember-glimmer/tests/integration/content-test.js index cfd60ffa548..b68c84302b0 100644 --- a/packages/ember-glimmer/tests/integration/content-test.js +++ b/packages/ember-glimmer/tests/integration/content-test.js @@ -495,17 +495,17 @@ class DynamicContentTest extends RenderingTest { this.assertStableRerender(); - // this.runTask(() => set(func, 'aProp', 'still a property on a function')); - // this.assertContent('still a property on a function'); - // this.assertInvariants(); + this.runTask(() => set(func, 'aProp', 'still a property on a function')); + this.assertContent('still a property on a function'); + this.assertInvariants(); - // func = () => {}; - // func.aProp = 'a prop on a new function'; + func = () => {}; + func.aProp = 'a prop on a new function'; - // this.runTask(() => set(this.context, 'func', func)); + this.runTask(() => set(this.context, 'func', func)); - // this.assertContent('a prop on a new function'); - // this.assertInvariants(); + this.assertContent('a prop on a new function'); + this.assertInvariants(); } } diff --git a/packages/ember-metal/lib/property_set.js b/packages/ember-metal/lib/property_set.js index e7adb0e89f2..9b284e293c5 100644 --- a/packages/ember-metal/lib/property_set.js +++ b/packages/ember-metal/lib/property_set.js @@ -67,7 +67,6 @@ export function set(obj, keyName, value, tolerant) { propertyDidChange(obj, keyName, meta); } - return value; } diff --git a/packages/ember-metal/lib/tags.js b/packages/ember-metal/lib/tags.js index 5e265cd9ad4..31d82c77bc3 100644 --- a/packages/ember-metal/lib/tags.js +++ b/packages/ember-metal/lib/tags.js @@ -13,7 +13,7 @@ function makeTag() { } export function tagForProperty(object, propertyKey, _meta) { - if (typeof object !== 'object' || object === null) { return CONSTANT_TAG; } + if ((typeof object !== 'object' && typeof object !== 'function') || object === null) { return CONSTANT_TAG; } let meta = _meta || metaFor(object); if (meta.isProxy()) { diff --git a/packages/ember-metal/lib/watch_key.js b/packages/ember-metal/lib/watch_key.js index da941d53852..be5362515bc 100644 --- a/packages/ember-metal/lib/watch_key.js +++ b/packages/ember-metal/lib/watch_key.js @@ -14,7 +14,7 @@ import { let handleMandatorySetter; export function watchKey(obj, keyName, meta) { - if (typeof obj !== 'object' || obj === null) { return; } + if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) { return; } let m = meta || metaFor(obj); let count = m.peekWatching(keyName) || 0; @@ -81,9 +81,8 @@ if (MANDATORY_SETTER) { } export function unwatchKey(obj, keyName, _meta) { - if (typeof obj !== 'object' || obj === null) { - return; - } + if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) { return; } + let meta = _meta || peekMeta(obj); // do nothing of this object has already been destroyed From 45211564ec60623b086765219de81af457293aa3 Mon Sep 17 00:00:00 2001 From: bekzod Date: Sat, 9 Sep 2017 17:54:29 +0500 Subject: [PATCH 2/2] make sure `unbound` helper works with function properties --- packages/ember-glimmer/lib/utils/references.js | 2 +- .../tests/integration/helpers/unbound-test.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/ember-glimmer/lib/utils/references.js b/packages/ember-glimmer/lib/utils/references.js index e360b08385a..5fe8b3e5bf4 100644 --- a/packages/ember-glimmer/lib/utils/references.js +++ b/packages/ember-glimmer/lib/utils/references.js @@ -398,7 +398,7 @@ export class InternalHelperReference extends CachedReference { // @implements PathReference export class UnboundReference extends ConstReference { static create(value) { - if (typeof value === 'object' && value !== null || typeof result === 'function') { + if (typeof value === 'object' && value !== null || typeof value === 'function') { return new UnboundReference(value); } else { return PrimitiveReference.create(value); diff --git a/packages/ember-glimmer/tests/integration/helpers/unbound-test.js b/packages/ember-glimmer/tests/integration/helpers/unbound-test.js index 1cd522ab512..59c16bbb1b8 100644 --- a/packages/ember-glimmer/tests/integration/helpers/unbound-test.js +++ b/packages/ember-glimmer/tests/integration/helpers/unbound-test.js @@ -142,6 +142,23 @@ moduleFor('Helpers test: {{unbound}}', class extends RenderingTest { this.assertHTML(escapedHtml); } + ['@test unbound works with function properties']() { + let func = function() {} + func.foo = 'WOOT'; + let parent = { func }; + this.render(`{{unbound func.foo}}`, parent); + + this.assertText('WOOT'); + + this.runTask(() => this.rerender()); + + this.assertText('WOOT'); + + this.runTask(() => set(this.context, 'func.foo', 'OOF')); + + this.assertText('WOOT'); + } + ['@skip helper form updates on parent re-render']() { this.render(`{{unbound foo}}`, { foo: 'BORK'