Skip to content

Commit

Permalink
Deprecate quoteless action names.
Browse files Browse the repository at this point in the history
Using quoteless action names has been deprecated. In 1.5+ this will
result in bound property lookup (allowing dynamic action names).

Reference:

emberjs#4276
emberjs#3936
  • Loading branch information
rwjblue committed Feb 2, 2014
1 parent 06ff8ee commit 2ef00a2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/ember-routing/lib/helpers/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
target = target.root;
}

if (options.boundProperty) {
Ember.deprecate("Using a quoteless parameter with {{action}} is deprecated. Please update to quoted usage '{{action \"" + actionName + "\"}}.", false);
}

Ember.run(function runRegisteredAction() {
if (target.send) {
target.send.apply(target, args(options.parameters, actionName));
Expand Down Expand Up @@ -302,6 +306,7 @@ Ember.onLoad('Ember.Handlebars', function(Handlebars) {
action.target = { root: root, target: target, options: options };
action.bubbles = hash.bubbles;
action.preventDefault = hash.preventDefault;
action.boundProperty = options.types[0] === "ID";

var actionId = ActionHelper.registerAction(actionName, action, hash.allowedKeys);
return new SafeString('data-ember-action="' + actionId + '"');
Expand Down
31 changes: 31 additions & 0 deletions packages/ember-routing/tests/helpers/action_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,34 @@ test("should respect preventDefault=false option if provided", function(){

equal(event.isDefaultPrevented(), false, "should not preventDefault");
});

test("a quoteless parameter as an action name", function(){
expect(2);

var triggeredAction;

view = Ember.View.create({
template: compile("<a id='oops-bound-param'' {{action ohNoeNotValid}}>Hi</a>")
});

var controller = Ember.Controller.extend({
actions: {
ohNoeNotValid: function() {
triggeredAction = true;
}
}
}).create();

Ember.run(function() {
view.set('controller', controller);
view.appendTo('#qunit-fixture');
});

expectDeprecation(function(){
Ember.run(function(){
view.$("#oops-bound-param").click();
});
},"Using a quoteless parameter with {{action}} is deprecated. Please update to quoted usage '{{action \"ohNoeNotValid\"}}." );

ok(triggeredAction, 'the action was triggered');
});

0 comments on commit 2ef00a2

Please sign in to comment.