Skip to content

Commit

Permalink
Merge pull request #15535 from emberjs/pr-15482
Browse files Browse the repository at this point in the history
[BUGFIX release] Fix rendering a property of a function
  • Loading branch information
rwjblue authored Jul 22, 2017
2 parents 8e7443f + 6492271 commit 37f6af1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/ember-glimmer/lib/utils/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions packages/ember-glimmer/tests/integration/content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 37f6af1

Please sign in to comment.