Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Handle mut cell action names. Fixes #11176 #11187

Merged
merged 1 commit into from
May 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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