From 1c8831e94b61821acac264d09b65d5ae9d18a833 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 4 Mar 2016 02:04:12 -0800 Subject: [PATCH 1/2] [BUGFIX release] Fixes `{{#with proxy as |foo|}}` This fixes an issue in HTMLBars where passing a truthy proxy (i.e. `{ isTruthy: true, ... }`) to `{{#with}}` would end up yielding the literal `true` rather than the proxy itself. The Glimmer implementation is unaffected by this bug. Fixes #13045 --- .../tests/integration/syntax/with-test.js | 28 +++++++++++++++++++ .../lib/hooks/link-render-node.js | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/ember-glimmer/tests/integration/syntax/with-test.js b/packages/ember-glimmer/tests/integration/syntax/with-test.js index 48053a68c2a..b8e45eebccc 100644 --- a/packages/ember-glimmer/tests/integration/syntax/with-test.js +++ b/packages/ember-glimmer/tests/integration/syntax/with-test.js @@ -129,6 +129,34 @@ moduleFor('Syntax test: {{#with as}}', class extends TogglingSyntaxConditionalsT this.assertText('No Thing bar'); } + ['@test can access alias of a proxy']() { + this.render(`{{#with proxyThing as |person|}}{{person.name}}{{/with}}`, { + proxyThing: { isTruthy: true, name: 'Tom Dale' } + }); + + this.assertText('Tom Dale'); + + this.runTask(() => this.rerender()); + + this.assertText('Tom Dale'); + + this.runTask(() => set(this.context, 'proxyThing.name', 'Yehuda Katz')); + + this.assertText('Yehuda Katz'); + + this.runTask(() => set(this.context, 'proxyThing.isTruthy', false)); + + this.assertText(''); + + this.runTask(() => set(this.context, 'proxyThing.name', 'Godfrey Chan')); + + this.assertText(''); + + this.runTask(() => set(this.context, 'proxyThing', { isTruthy: true, name: 'Tom Dale' })); + + this.assertText('Tom Dale'); + } + ['@test can access alias of an array']() { this.render(`{{#with arrayThing as |words|}}{{#each words as |word|}}{{word}}{{/each}}{{/with}}`, { arrayThing: emberA(['Hello', ' ', 'world']) diff --git a/packages/ember-htmlbars/lib/hooks/link-render-node.js b/packages/ember-htmlbars/lib/hooks/link-render-node.js index 4351f90c6cc..59504bff6f7 100644 --- a/packages/ember-htmlbars/lib/hooks/link-render-node.js +++ b/packages/ember-htmlbars/lib/hooks/link-render-node.js @@ -91,7 +91,7 @@ function shouldDisplay(predicate, coercer) { } if (typeof isTruthyVal === 'boolean') { - return isTruthyVal; + return isTruthyVal ? coercer(predicateVal) : false; } return coercer(predicateVal); From 29943af019a2c96b657cb4d84c64f0c415695958 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 4 Mar 2016 08:58:31 -0800 Subject: [PATCH 2/2] Coercer array values too for correctness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As far as I can tell, this doesn’t have any meaningful effect in practice. --- packages/ember-htmlbars/lib/hooks/link-render-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ember-htmlbars/lib/hooks/link-render-node.js b/packages/ember-htmlbars/lib/hooks/link-render-node.js index 59504bff6f7..dd661f355d7 100644 --- a/packages/ember-htmlbars/lib/hooks/link-render-node.js +++ b/packages/ember-htmlbars/lib/hooks/link-render-node.js @@ -87,7 +87,7 @@ function shouldDisplay(predicate, coercer) { let isTruthyVal = read(isTruthy); if (isArray(predicateVal)) { - return lengthVal > 0 ? predicateVal : false; + return lengthVal > 0 ? coercer(predicateVal) : false; } if (typeof isTruthyVal === 'boolean') {