Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Fix rendering a property of a function #15535

Merged
merged 2 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I missed that? I didn't comment it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was trying to do INUR (which is likely what prompted the fixing of the updating side also), so my guess is that the update/reset parts here are just commented out.

// 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