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

[BUGFIX beta] Remove double loop over attrs to create a component. #12297

Merged
merged 1 commit into from
Sep 5, 2015
Merged
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
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