From ea1d3011023b341b767ae640ca34251f1b012a0b Mon Sep 17 00:00:00 2001 From: bekzod Date: Sun, 9 Jul 2017 19:50:18 +0500 Subject: [PATCH 1/2] [BUGFIX release] enable templates read a property from a function --- packages/ember-glimmer/lib/utils/references.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ember-glimmer/lib/utils/references.js b/packages/ember-glimmer/lib/utils/references.js index fda919586ab..e360b08385a 100644 --- a/packages/ember-glimmer/lib/utils/references.js +++ b/packages/ember-glimmer/lib/utils/references.js @@ -213,11 +213,13 @@ export class NestedPropertyReference extends PropertyReference { _parentObjectTag.update(tagForProperty(parentValue, _propertyKey)); - if (typeof parentValue === 'string' && _propertyKey === 'length') { + let parentValueType = typeof parentValue; + + if (parentValueType === 'string' && _propertyKey === 'length') { return parentValue.length; } - if (typeof parentValue === 'object' && parentValue) { + if (parentValueType === 'object' && parentValue !== null || parentValueType === 'function') { if (MANDATORY_SETTER) { watchKey(parentValue, _propertyKey); } @@ -315,7 +317,7 @@ export class SimpleHelperReference extends CachedReference { let result = helper(positionalValue, namedValue); - if (typeof result === 'object' && result !== null) { + if (typeof result === 'object' && result !== null || typeof result === 'function') { return new RootReference(result); } else { return PrimitiveReference.create(result); @@ -396,7 +398,7 @@ export class InternalHelperReference extends CachedReference { // @implements PathReference export class UnboundReference extends ConstReference { static create(value) { - if (typeof value === 'object' && value !== null) { + if (typeof value === 'object' && value !== null || typeof result === 'function') { return new UnboundReference(value); } else { return PrimitiveReference.create(value); From 6492271acc324e8d341184ea07898d3c8ecf823e Mon Sep 17 00:00:00 2001 From: Kyle Turney Date: Fri, 16 Dec 2016 17:24:06 -0600 Subject: [PATCH 2/2] [BUGFIX release] failing test for reading a property off of a function --- .../tests/integration/content-test.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/ember-glimmer/tests/integration/content-test.js b/packages/ember-glimmer/tests/integration/content-test.js index 542a05e12a2..cfd60ffa548 100644 --- a/packages/ember-glimmer/tests/integration/content-test.js +++ b/packages/ember-glimmer/tests/integration/content-test.js @@ -484,6 +484,29 @@ class DynamicContentTest extends RenderingTest { this.assertContent('hello'); this.assertInvariants(); } + + ['@test it can render a property on a function']() { + let func = () => {}; + func.aProp = 'this is a property on a function'; + + this.renderPath('func.aProp', { func }); + + this.assertContent('this is a property on a function'); + + this.assertStableRerender(); + + // 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'; + + // this.runTask(() => set(this.context, 'func', func)); + + // this.assertContent('a prop on a new function'); + // this.assertInvariants(); + } } const EMPTY = {};