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

[CLEANUP beta] Remove context switching {{each}} helper variant #11850

Merged
merged 1 commit into from Jul 21, 2015
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
15 changes: 1 addition & 14 deletions packages/ember-htmlbars/lib/helpers/each.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Ember from 'ember-metal/core';
import Error from 'ember-metal/error';
import normalizeSelf from 'ember-htmlbars/utils/normalize-self';
import shouldDisplay from 'ember-views/streams/should_display';
import decodeEachKey from 'ember-htmlbars/utils/decode-each-key';

Expand Down Expand Up @@ -75,25 +73,16 @@ export default function eachHelper(params, hash, blocks) {
var list = params[0];
var keyPath = hash.key;

if (blocks.template.arity === 0) {
Ember.deprecate(deprecation, false, { id: 'ember-htmlbars.each-helper-arity', until: '3.0.0' });
}

if (shouldDisplay(list)) {
let seenKeys = {};
forEach(list, (item, i) => {
var self;
if (blocks.template.arity === 0) {
self = normalizeSelf(item);
}

var key = decodeEachKey(item, keyPath, i);
if (seenKeys[key] === true) {
throw new Error(`Duplicate key found ('${key}') for '{{each}}' helper, please use a unique key or switch to '{{#each model key="@index"}}{{/each}}'.`);
} else {
seenKeys[key] = true;
}
blocks.template.yieldItem(key, [item, i], self);
blocks.template.yieldItem(key, [item, i]);
});
} else if (blocks.inverse.yield) {
blocks.inverse.yield();
Expand All @@ -103,5 +92,3 @@ export default function eachHelper(params, hash, blocks) {
function forEach(iterable, cb) {
return iterable.forEach ? iterable.forEach(cb) : Array.prototype.forEach.call(iterable, cb);
}

export var deprecation = 'Using the context switching form of {{each}} is deprecated. Please use the keyword form (`{{#each items as |item|}}`) instead.';
17 changes: 5 additions & 12 deletions packages/ember-htmlbars/tests/compat/make_bound_helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import { dasherize } from 'ember-runtime/system/string';

import EmberHandlebars from 'ember-htmlbars/compat';
import { deprecation as eachDeprecation } from 'ember-htmlbars/helpers/each';

var compile, helpers, helper;
compile = EmberHandlebars.compile;
Expand Down Expand Up @@ -52,12 +51,10 @@ QUnit.module('ember-htmlbars: compat - makeBoundHelper', {
});

QUnit.test('primitives should work correctly [DEPRECATED]', function() {
expectDeprecation(eachDeprecation);

view = EmberView.create({
prims: Ember.A(['string', 12]),

template: compile('{{#each view.prims}}{{#if this}}inside-if{{/if}}{{/each}}')
template: compile('{{#each view.prims as |prim|}}{{#if prim}}inside-if{{/if}}{{/each}}')
});

runAppend(view);
Expand Down Expand Up @@ -486,12 +483,10 @@ QUnit.test('bound helpers can handle nulls in array (with primitives) [DEPRECATE
controller: EmberObject.create({
things: A([null, 0, undefined, false, 'OMG'])
}),
template: compile('{{#each things}}{{this}}|{{reverse this}} {{/each}}{{#each things as |thing|}}{{thing}}|{{reverse thing}} {{/each}}')
template: compile('{{#each things as |thing|}}{{thing}}|{{reverse thing}} {{/each}}{{#each things as |thing|}}{{thing}}|{{reverse thing}} {{/each}}')
});

expectDeprecation(function() {
runAppend(view);
}, eachDeprecation);
runAppend(view);

equal(view.$().text(), '|NOPE 0|NOPE |NOPE false|NOPE OMG|GMO |NOPE 0|NOPE |NOPE false|NOPE OMG|GMO ', 'helper output is correct');

Expand All @@ -514,12 +509,10 @@ QUnit.test('bound helpers can handle nulls in array (with objects)', function()
controller: EmberObject.create({
things: A([null, { foo: 5 }])
}),
template: compile('{{#each things}}{{foo}}|{{print-foo this}} {{/each}}{{#each things as |thing|}}{{thing.foo}}|{{print-foo thing}} {{/each}}')
template: compile('{{#each things as |thing|}}{{thing.foo}}|{{print-foo thing}} {{/each}}{{#each things as |thing|}}{{thing.foo}}|{{print-foo thing}} {{/each}}')
});

expectDeprecation(function() {
runAppend(view);
}, eachDeprecation);
runAppend(view);

equal(view.$().text(), '|NOPE 5|5 |NOPE 5|5 ', 'helper output is correct');

Expand Down
6 changes: 2 additions & 4 deletions packages/ember-htmlbars/tests/helpers/collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ QUnit.test('should work inside a bound {{#if}}', function() {

QUnit.test('should pass content as context when using {{#each}} helper [DEPRECATED]', function() {
view = EmberView.create({
template: compile('{{#each view.releases}}Mac OS X {{version}}: {{name}} {{/each}}'),
template: compile('{{#each view.releases as |release|}}Mac OS X {{release.version}}: {{release.name}} {{/each}}'),

releases: A([
{ version: '10.7',
Expand All @@ -451,9 +451,7 @@ QUnit.test('should pass content as context when using {{#each}} helper [DEPRECAT
])
});

expectDeprecation(function() {
runAppend(view);
}, 'Using the context switching form of {{each}} is deprecated. Please use the keyword form (`{{#each items as |item|}}`) instead.');
runAppend(view);

equal(view.$().text(), 'Mac OS X 10.7: Lion Mac OS X 10.6: Snow Leopard Mac OS X 10.5: Leopard ', 'prints each item in sequence');
});
Expand Down
Loading