Skip to content

Commit

Permalink
Merge pull request #12542 from Serabe/fix-12537
Browse files Browse the repository at this point in the history
[BUGFIX canary] Create new hash when merging parameters hashes in components
  • Loading branch information
rwjblue committed Nov 1, 2015
2 parents 0f51f7d + 195957f commit 10d599e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/ember-htmlbars/lib/hooks/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
COMPONENT_PATH,
COMPONENT_HASH,
isComponentCell,
mergeHash,
mergeInNewHash,
} from 'ember-htmlbars/keywords/closure-component';

var IS_ANGLE_CACHE = new Cache(1000, function(key) {
Expand All @@ -33,7 +33,7 @@ export default function componentHook(renderNode, env, scope, _tagName, params,
let componentCell = stream.value();
if (isComponentCell(componentCell)) {
tagName = componentCell[COMPONENT_PATH];
attrs = mergeHash(componentCell[COMPONENT_HASH], attrs);
attrs = mergeInNewHash(componentCell[COMPONENT_HASH], attrs);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/ember-htmlbars/lib/keywords/closure-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function createNestedClosureComponentCell(componentCell, params, hash) {

return {
[COMPONENT_PATH]: componentCell[COMPONENT_PATH],
[COMPONENT_HASH]: mergeHash(componentCell[COMPONENT_HASH], hash),
[COMPONENT_HASH]: mergeInNewHash(componentCell[COMPONENT_HASH], hash),
[COMPONENT_POSITIONAL_PARAMS]: positionalParams,
[COMPONENT_CELL]: true
};
Expand Down Expand Up @@ -117,6 +117,6 @@ function getPositionalParams(container, componentPath) {
}
}

export function mergeHash(original, updates) {
return assign(original, updates);
export function mergeInNewHash(original, updates) {
return assign({}, original, updates);
}
4 changes: 2 additions & 2 deletions packages/ember-htmlbars/lib/keywords/element-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
COMPONENT_POSITIONAL_PARAMS,
COMPONENT_HASH,
isComponentCell,
mergeHash,
mergeInNewHash,
} from './closure-component';
import { processPositionalParams } from 'ember-htmlbars/utils/extract-positional-params';

Expand Down Expand Up @@ -63,7 +63,7 @@ function render(morph, env, scope, [path, ...params], hash, template, inverse, v
// This needs to be done in each nesting level to avoid raising assertions
processPositionalParams(null, positionalParams, params, hash);
params = [];
hash = mergeHash(closureComponent[COMPONENT_HASH], hash);
hash = mergeInNewHash(closureComponent[COMPONENT_HASH], hash);
}

let templates = { default: template, inverse };
Expand Down
21 changes: 21 additions & 0 deletions packages/ember-htmlbars/tests/helpers/closure_component_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,25 @@ if (isEnabled('ember-contextual-components')) {
runAppend(component);
equal(component.$().text(), expectedText, '-looked-up component rendered');
});

QUnit.test('adding parameters to a closure component\'s instance does not add it to other instances', function(assert) {
registry.register(
'template:components/select-box',
compile('{{yield (hash option=(component "select-box-option"))}}')
);

registry.register(
'template:components/select-box-option',
compile('{{label}}')
);

let template = compile(
'{{#select-box as |sb|}}{{sb.option label="Foo"}}{{sb.option}}{{/select-box}}'
);

component = Component.extend({ container, template }).create();

runAppend(component);
equal(component.$().text(), 'Foo', 'there is only one Foo');
});
}

0 comments on commit 10d599e

Please sign in to comment.