Skip to content

Commit

Permalink
Merge pull request #11455 from stefanpenner/enumerable-utils-cleanup
Browse files Browse the repository at this point in the history
  (╯°□°)╯︵ sʃıʇn ǝʃqɐɹǝɯnuǝ
  • Loading branch information
rwjblue committed Jun 15, 2015
2 parents 8f53f8e + 0d0b16a commit 0ba7856
Show file tree
Hide file tree
Showing 50 changed files with 251 additions and 531 deletions.
3 changes: 1 addition & 2 deletions packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import create from "ember-metal/platform/create";
import run from "ember-metal/run_loop";
import { canInvoke } from "ember-metal/utils";
import Controller from "ember-runtime/controllers/controller";
import { map } from "ember-metal/enumerable_utils";
import ObjectController from "ember-runtime/controllers/object_controller";
import ArrayController from "ember-runtime/controllers/array_controller";
import Renderer from "ember-metal-views/renderer";
Expand Down Expand Up @@ -1151,7 +1150,7 @@ function logLibraryVersions() {
Ember.LOG_VERSION = false;
var libs = Ember.libraries._registry;

var nameLengths = map(libs, function(item) {
var nameLengths = libs.map(function(item) {
return get(item, 'name.length');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { get } from "ember-metal/property_get";
import { forEach } from "ember-metal/enumerable_utils";
import normalizeSelf from "ember-htmlbars/utils/normalize-self";
import decodeEachKey from "ember-htmlbars/utils/decode-each-key";

Expand All @@ -13,7 +12,7 @@ export default function legacyEachWithControllerHelper(params, hash, blocks) {
return;
}

forEach(list, function(item, i) {
list.forEach(function(item, i) {
var self;

if (blocks.template.arity === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { forEach } from "ember-metal/enumerable_utils";
import shouldDisplay from "ember-views/streams/should_display";
import decodeEachKey from "ember-htmlbars/utils/decode-each-key";

Expand All @@ -8,7 +7,7 @@ export default function legacyEachWithKeywordHelper(params, hash, blocks) {
var legacyKeyword = hash['-legacy-keyword'];

if (shouldDisplay(list)) {
forEach(list, function(item, i) {
list.forEach(function(item, i) {
var self;
if (legacyKeyword) {
self = bindKeyword(self, legacyKeyword, item);
Expand Down
7 changes: 5 additions & 2 deletions packages/ember-htmlbars/lib/helpers/each.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { forEach } from "ember-metal/enumerable_utils";
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 @@ -84,7 +83,7 @@ export default function eachHelper(params, hash, blocks) {
}

if (shouldDisplay(list)) {
forEach(list, function(item, i) {
forEach(list, (item, i) => {
var self;
if (blocks.template.arity === 0) {
self = normalizeSelf(item);
Expand All @@ -98,4 +97,8 @@ 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.";
7 changes: 4 additions & 3 deletions packages/ember-htmlbars/lib/streams/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import getValue from "ember-htmlbars/hooks/get-value";
// We don't want to leak mutable cells into helpers, which
// are pure functions that can only work with values.
export function getArrayValues(params) {
let out = [];
for (let i=0, l=params.length; i<l; i++) {
out.push(getValue(params[i]));
let l = params.length;
let out = new Array(l);
for (let i=0; i<l; i++) {
out[i] = getValue(params[i]);
}

return out;
Expand Down
13 changes: 6 additions & 7 deletions packages/ember-htmlbars/tests/helpers/if_unless_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ArrayProxy from "ember-runtime/system/array_proxy";
import { set } from 'ember-metal/property_set';
import { fmt } from 'ember-runtime/system/string';
import { typeOf } from 'ember-runtime/utils';
import { forEach } from 'ember-metal/enumerable_utils';
import { runAppend, runDestroy } from "ember-runtime/tests/utils";

var originalLookup = Ember.lookup;
Expand Down Expand Up @@ -282,7 +281,7 @@ QUnit.test('should update the block when object passed to #unless helper changes

var tests = [false, null, undefined, [], '', 0];

forEach(tests, function(val) {
tests.forEach(function(val) {
run(function() {
set(view, 'onDrugs', val);
});
Expand Down Expand Up @@ -336,7 +335,7 @@ QUnit.test('should update the block when object passed to #if helper changes', f

var tests = [false, null, undefined, [], '', 0];

forEach(tests, function(val) {
tests.forEach(function(val) {
run(function() {
set(view, 'inception', val);
});
Expand Down Expand Up @@ -371,7 +370,7 @@ QUnit.test('should update the block when object passed to #if helper changes and

var tests = [false, null, undefined, [], '', 0];

forEach(tests, function(val) {
tests.forEach(function(val) {
run(function() {
set(view, 'inception', val);
});
Expand Down Expand Up @@ -447,7 +446,7 @@ QUnit.test('should update the block when object passed to #unless helper changes

var tests = [false, null, undefined, [], '', 0];

forEach(tests, function(val) {
tests.forEach(function(val) {
run(function() {
set(view, 'onDrugs', val);
});
Expand Down Expand Up @@ -502,7 +501,7 @@ QUnit.test('should update the block when object passed to #if helper changes', f

var tests = [false, null, undefined, [], '', 0];

forEach(tests, function(val) {
tests.forEach(function(val) {
run(function() {
set(view, 'inception', val);
});
Expand Down Expand Up @@ -537,7 +536,7 @@ QUnit.test('should update the block when object passed to #if helper changes and

var tests = [false, null, undefined, [], '', 0];

forEach(tests, function(val) {
tests.forEach(function(val) {
run(function() {
set(view, 'inception', val);
});
Expand Down
4 changes: 1 addition & 3 deletions packages/ember-metal-views/lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { set } from "ember-metal/property_set";
import { assign } from "ember-metal/merge";
import setProperties from "ember-metal/set_properties";
import buildComponentTemplate from "ember-views/system/build-component-template";
import { indexOf } from "ember-metal/enumerable_utils";
//import { deprecation } from "ember-views/compat/attrs-proxy";

function Renderer(_helper) {
this._dom = _helper;
Expand Down Expand Up @@ -84,7 +82,7 @@ Renderer.prototype.dispatchLifecycleHooks =
Renderer.prototype.ensureViewNotRendering =
function Renderer_ensureViewNotRendering(view) {
var env = view.ownerView.env;
if (env && indexOf(env.renderedViews, view.elementId) !== -1) {
if (env && env.renderedViews.indexOf(view.elementId) !== -1) {
throw new Error('Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.');
}
};
Expand Down
Loading

0 comments on commit 0ba7856

Please sign in to comment.