Skip to content

Commit

Permalink
sendAction is compatible with improved actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed May 11, 2015
1 parent 7379459 commit 7301768
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/ember-views/lib/views/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,26 @@ var Component = View.extend(TargetActionSupport, ComponentTemplateDeprecation, {
actionName = get(this, 'action');
Ember.assert("The default action was triggered on the component " + this.toString() +
", but the action name (" + actionName + ") was not a string.",
isNone(actionName) || typeof actionName === 'string');
isNone(actionName) || typeof actionName === 'string' || typeof actionName === 'function');
} else {
actionName = get(this, 'attrs.' + action) || get(this, action);
Ember.assert("The " + action + " action was triggered on the component " +
this.toString() + ", but the action name (" + actionName +
") was not a string.",
isNone(actionName) || typeof actionName === 'string');
isNone(actionName) || typeof actionName === 'string' || typeof actionName === 'function');
}

// If no action name for that action could be found, just abort.
if (actionName === undefined) { return; }

this.triggerAction({
action: actionName,
actionContext: contexts
});
if (typeof actionName === 'function') {
actionName.apply(null, contexts);
} else {
this.triggerAction({
action: actionName,
actionContext: contexts
});
}
},

send(actionName, ...args) {
Expand Down
19 changes: 19 additions & 0 deletions packages/ember-views/tests/views/component_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ QUnit.test("Calling sendAction on a component with an action defined calls send
equal(actionCounts['addItem'], 1, "addItem event was sent once");
});

QUnit.test("Calling sendAction on a component with a function calls the function", function() {
expect(1);
set(component, 'action', function() {
ok(true, 'function is called');
});

component.sendAction();
});

QUnit.test("Calling sendAction on a component with a function calls the function with arguments", function() {
expect(1);
var argument = {};
set(component, 'action', function(actualArgument) {
equal(actualArgument, argument, 'argument is passed');
});

component.sendAction('action', argument);
});

QUnit.test("Calling sendAction with a named action uses the component's property as the action name", function() {
set(component, 'playing', "didStartPlaying");
set(component, 'action', "didDoSomeBusiness");
Expand Down

0 comments on commit 7301768

Please sign in to comment.