Skip to content

Commit

Permalink
Merge pull request #12297 from rwjblue/one-loop-during-create
Browse files Browse the repository at this point in the history
[BUGFIX beta] Remove double loop over attrs to create a component.
  • Loading branch information
rwjblue committed Sep 5, 2015
2 parents f0bd8ed + f4a3059 commit db23f43
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/ember-htmlbars/lib/node-managers/component-node-manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assert, warn, runInDebug } from 'ember-metal/debug';
import assign from 'ember-metal/assign';
import buildComponentTemplate from 'ember-views/system/build-component-template';
import getCellOrValue from 'ember-htmlbars/hooks/get-cell-or-value';
import { get } from 'ember-metal/property_get';
Expand Down Expand Up @@ -255,17 +254,14 @@ ComponentNodeManager.prototype.destroy = function ComponentNodeManager_destroy()
component.destroy();
};

export function createComponent(_component, isAngleBracket, _props, renderNode, env, attrs = {}) {
let props = assign({}, _props);

let snapshot = takeSnapshot(attrs);
props.attrs = snapshot;

export function createComponent(_component, isAngleBracket, props, renderNode, env, attrs = {}) {
if (!isAngleBracket) {
assert('controller= is no longer supported', !('controller' in attrs));

mergeBindings(props, snapshot);
snapshotAndUpdateTarget(attrs, props);
} else {
props.attrs = takeSnapshot(attrs);

props._isAngleBracket = true;
}

Expand Down Expand Up @@ -311,9 +307,13 @@ export function takeLegacySnapshot(attrs) {
return hash;
}

function mergeBindings(target, attrs) {
for (var prop in attrs) {
if (!attrs.hasOwnProperty(prop)) { continue; }
function snapshotAndUpdateTarget(rawAttrs, target) {
let attrs = {};

for (var prop in rawAttrs) {
let value = getCellOrValue(rawAttrs[prop]);
attrs[prop] = value;

// when `attrs` is an actual value being set in the
// attrs hash (`{{foo-bar attrs="blah"}}`) we cannot
// set `"blah"` to the root of the target because
Expand All @@ -322,16 +322,15 @@ function mergeBindings(target, attrs) {
warn(`Invoking a component with a hash attribute named \`attrs\` is not supported. Please refactor usage of ${target} to avoid passing \`attrs\` as a hash parameter.`, false, { id: 'ember-htmlbars.component-unsupported-attrs' });
continue;
}
let value = attrs[prop];

if (value && value[MUTABLE_CELL]) {
target[prop] = value.value;
} else {
target[prop] = value;
value = value.value;
}

target[prop] = value;
}

return target;
return target.attrs = attrs;
}

function buildChildEnv(state, env) {
Expand Down

0 comments on commit db23f43

Please sign in to comment.