From 626339c61c1d3a4a4cc89e5cddd6b99c969f8969 Mon Sep 17 00:00:00 2001 From: Spencer P Date: Mon, 22 Feb 2016 13:11:13 -0800 Subject: [PATCH] [bugfix BETA] #with array support --- .../tests/integration/syntax/with-test.js | 23 +++++++++++++++++++ .../lib/hooks/link-render-node.js | 2 +- 2 files changed, 24 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 97522efcbd3..5417a892ed5 100644 --- a/packages/ember-glimmer/tests/integration/syntax/with-test.js +++ b/packages/ember-glimmer/tests/integration/syntax/with-test.js @@ -122,6 +122,29 @@ moduleFor('Syntax test: {{#with as}}', class extends SharedConditionalsTest{ this.assertText('No Thing bar'); } + ['@test can access alias of an array']() { + this.render(`{{#with arrayThing as |thing|}}{{#each thing as |value|}}{{value}}{{/each}}{{/with}}`, { + arrayThing: ['a', 'b', 'c', 'd'] + }); + + this.assertText('abcd'); + + this.runTask(() => this.rerender()); + + this.assertText('abcd'); + } + + ['@test empty arrays yield inverse']() { + this.render(`{{#with arrayThing as |thing|}}{{thing}}{{else}}Empty Array{{/with}}`, { + arrayThing: [] + }); + + this.assertText('Empty Array'); + + this.runTask(() => this.rerender()); + + this.assertText('Empty Array'); + } }, BASIC_TRUTHY_TESTS, BASIC_FALSY_TESTS); moduleFor('Syntax test: Multiple {{#with as}} helpers', class extends RenderingTest { diff --git a/packages/ember-htmlbars/lib/hooks/link-render-node.js b/packages/ember-htmlbars/lib/hooks/link-render-node.js index 9c19a8867a0..4351f90c6cc 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; + return lengthVal > 0 ? predicateVal : false; } if (typeof isTruthyVal === 'boolean') {