Skip to content

Commit

Permalink
Merge pull request #11260 from csantero/array-arg
Browse files Browse the repository at this point in the history
[BUGFIX beta] fix passing array argument to action helper
  • Loading branch information
rwjblue committed May 23, 2015
2 parents 37f4325 + cdc44b7 commit 84689f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function createClosureAction(target, action, valuePath, actionArguments) {
closureAction = function() {
var args = actionArguments;
if (arguments.length > 0) {
args = actionArguments.concat(...arguments);
var passedArguments = Array.prototype.slice.apply(arguments);
args = actionArguments.concat(passedArguments);
}
if (valuePath && args.length > 0) {
args[0] = get(args[0], valuePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ if (Ember.FEATURES.isEnabled("ember-routing-htmlbars-improved-actions")) {
innerComponent.fireAction();
});

QUnit.test("array arguments are passed correctly to action", function(assert) {
assert.expect(3);

const first = 'foo';
const second = [3, 5];
const third = [4, 9];

innerComponent = EmberComponent.extend({
fireAction() {
this.attrs.submit(second, third);
}
}).create();

outerComponent = EmberComponent.extend({
layout: compile(`
{{view innerComponent submit=(action outerSubmit first)}}
`),
innerComponent,
value: '',
outerSubmit(actualFirst, actualSecond, actualThird) {
assert.equal(actualFirst, first, 'action has the correct first arg');
assert.equal(actualSecond, second, 'action has the correct second arg');
assert.equal(actualThird, third, 'action has the correct third arg');
}
}).create();

runAppend(outerComponent);

run(function() {
outerComponent.set('first', first);
outerComponent.set('second', second);
});

innerComponent.fireAction();
});

QUnit.test("mut values can be wrapped in actions, are settable", function(assert) {
assert.expect(1);

Expand Down

0 comments on commit 84689f4

Please sign in to comment.