Skip to content

Commit

Permalink
Merge pull request #12712 from Serabe/fix/positional-params-on-rerender
Browse files Browse the repository at this point in the history
[BUGFIX beta] Create a new hash parameter when creating a component cell
  • Loading branch information
rwjblue committed Dec 21, 2015
2 parents 01b1107 + 4e7fe48 commit c3a8dcd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/ember-htmlbars/lib/hooks/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { assert } from 'ember-metal/debug';
import ComponentNodeManager from 'ember-htmlbars/node-managers/component-node-manager';
import buildComponentTemplate, { buildHTMLTemplate } from 'ember-views/system/build-component-template';
import lookupComponent from 'ember-htmlbars/utils/lookup-component';
import assign from 'ember-metal/assign';
import EmptyObject from 'ember-metal/empty_object';
import Cache from 'ember-metal/cache';
import {
CONTAINS_DASH_CACHE,
Expand Down Expand Up @@ -42,9 +44,10 @@ export default function componentHook(renderNode, env, scope, _tagName, params,
* on top of the closure component attributes.
*
*/
processPositionalParamsFromCell(componentCell, params, attrs);
let newAttrs = assign(new EmptyObject(), attrs);
processPositionalParamsFromCell(componentCell, params, newAttrs);
params = [];
attrs = mergeInNewHash(componentCell[COMPONENT_HASH], attrs);
attrs = mergeInNewHash(componentCell[COMPONENT_HASH], newAttrs);
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/ember-htmlbars/lib/keywords/closure-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { assert } from 'ember-metal/debug';
import isNone from 'ember-metal/is_none';
import symbol from 'ember-metal/symbol';
import BasicStream from 'ember-metal/streams/stream';
import EmptyObject from 'ember-metal/empty_object';
import { read } from 'ember-metal/streams/utils';
import { labelForSubexpr } from 'ember-htmlbars/hooks/subexpr';
import assign from 'ember-metal/assign';
Expand Down Expand Up @@ -54,12 +55,14 @@ function createClosureComponentCell(env, originalComponentPath, params, hash, la
assert(`Component path cannot be null in ${label}`,
!isNone(componentPath));

let newHash = assign(new EmptyObject(), hash);

if (isComponentCell(componentPath)) {
return createNestedClosureComponentCell(componentPath, params, hash);
return createNestedClosureComponentCell(componentPath, params, newHash);
} else {
assert(`The component helper cannot be used without a valid component name. You used "${componentPath}" via ${label}`,
isValidComponentPath(env, componentPath));
return createNewClosureComponentCell(env, componentPath, params, hash);
return createNewClosureComponentCell(env, componentPath, params, newHash);
}
}

Expand Down
32 changes: 32 additions & 0 deletions packages/ember-htmlbars/tests/helpers/closure_component_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,38 @@ if (isEnabled('ember-contextual-components')) {
}, `You cannot specify both a positional param (at position 0) and the hash argument \`name\`.`);
});

QUnit.test('conflicting positional and hash parameters does not raise and assertion if rerendered', function() {
let LookedUp = Component.extend();
LookedUp.reopenClass({
positionalParams: ['name']
});
owner.register(
'component:-looked-up',
LookedUp
);
owner.register(
'template:components/-looked-up',
compile(`{{greeting}} {{name}}`)
);

let template = compile(
`{{component (component "-looked-up" name greeting="Hodi")}}`
);

component = Component.extend({
[OWNER]: owner,
template,
name: 'Hodari'
}).create();

runAppend(component);
equal(component.$().text(), 'Hodi Hodari', 'component is rendered');

run(() => component.set('name', 'Sergio'));

equal(component.$().text(), 'Hodi Sergio', 'component is rendered');
});

QUnit.test('conflicting positional and hash parameters does not raise and assertion if in the different closure', function() {
let LookedUp = Component.extend();
LookedUp.reopenClass({
Expand Down

0 comments on commit c3a8dcd

Please sign in to comment.