diff --git a/packages/ember-views/lib/views/component.js b/packages/ember-views/lib/views/component.js index af5d3da59fe..4bb0de2f383 100644 --- a/packages/ember-views/lib/views/component.js +++ b/packages/ember-views/lib/views/component.js @@ -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) { diff --git a/packages/ember-views/tests/views/component_test.js b/packages/ember-views/tests/views/component_test.js index 93d15890890..29afb152f9d 100644 --- a/packages/ember-views/tests/views/component_test.js +++ b/packages/ember-views/tests/views/component_test.js @@ -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");