Skip to content

Commit

Permalink
[BUGFIX beta] Handle mut cell action names. Fixes #11176
Browse files Browse the repository at this point in the history
(cherry picked from commit 458cbeb)
  • Loading branch information
mixonic authored and rwjblue committed May 18, 2015
1 parent b31e47e commit 03a3f0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/ember-views/lib/views/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ import isNone from 'ember-metal/is_none';

import { computed } from "ember-metal/computed";

import { MUTABLE_CELL } from "ember-views/compat/attrs-proxy";

function validateAction(component, actionName) {
if (actionName && actionName[MUTABLE_CELL]) {
actionName = actionName.value;
}
Ember.assert("The default action was triggered on the component " + component.toString() +
", but the action name (" + actionName + ") was not a string.",
isNone(actionName) || typeof actionName === 'string' || typeof actionName === 'function');
return actionName;
}

/**
@module ember
@submodule ember-views
Expand Down Expand Up @@ -262,17 +274,10 @@ var Component = View.extend(TargetActionSupport, ComponentTemplateDeprecation, {

// Send the default action
if (action === undefined) {
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' || 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' || typeof actionName === 'function');
action = 'action';
}
actionName = get(this, 'attrs.' + action) || get(this, action);
actionName = validateAction(this, actionName);

// If no action name for that action could be found, just abort.
if (actionName === undefined) { return; }
Expand Down
16 changes: 16 additions & 0 deletions packages/ember-views/tests/views/component_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { get } from "ember-metal/property_get";
import EmberView from "ember-views/views/view";
import Component from "ember-views/views/component";

import { MUTABLE_CELL } from "ember-views/compat/attrs-proxy";

var a_slice = Array.prototype.slice;

var component, controller, actionCounts, sendCount, actionArguments;
Expand Down Expand Up @@ -155,6 +157,20 @@ QUnit.test("Calling sendAction on a component with a function calls the function
component.sendAction('action', argument);
});

QUnit.test("Calling sendAction on a component with a mut attr calls the function with arguments", function() {
var mut = {
value: 'didStartPlaying',
[MUTABLE_CELL]: true
};
set(component, 'playing', null);
set(component, 'attrs', { playing: mut });

component.sendAction('playing');

equal(sendCount, 1, "send was called once");
equal(actionCounts['didStartPlaying'], 1, "named action was sent");
});

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 03a3f0e

Please sign in to comment.