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

enable templates read a property from a function #15482

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/utils/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions packages/ember-glimmer/tests/integration/content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
17 changes: 17 additions & 0 deletions packages/ember-glimmer/tests/integration/helpers/unbound-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion packages/ember-metal/lib/property_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function set(obj, keyName, value, tolerant) {

propertyDidChange(obj, keyName, meta);
}

return value;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ember-metal/lib/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
7 changes: 3 additions & 4 deletions packages/ember-metal/lib/watch_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down