Skip to content

Commit

Permalink
Stash view and context on event object in action handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dgeb committed Feb 28, 2012
1 parent 31f6780 commit 657a266
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/ember-handlebars/lib/helpers/action.js
Expand Up @@ -12,10 +12,13 @@ ActionHelper.registerAction = function(actionName, eventName, target, view, cont
ActionHelper.registeredActions[actionId] = { ActionHelper.registeredActions[actionId] = {
eventName: eventName, eventName: eventName,
handler: function(event) { handler: function(event) {
event.view = view;
event.context = context;

if ('function' === typeof target.send) { if ('function' === typeof target.send) {
return target.send(actionName, { view: view, event: event, context: context }); return target.send(actionName, { event: event });
} else { } else {
return target[actionName].call(target, view, event, context); return target[actionName].call(target, event);
} }
} }
}; };
Expand Down
8 changes: 3 additions & 5 deletions packages/ember-handlebars/tests/helpers/action_test.js
Expand Up @@ -272,11 +272,9 @@ test("should send the view, event and current Handlebars context to the action",
var passedContext; var passedContext;


var aTarget = Ember.View.create({ var aTarget = Ember.View.create({
edit: function(view, event, context) { edit: function(event) {
passedTarget = this; passedTarget = this;
passedView = view;
passedEvent = event; passedEvent = event;
passedContext = context;
} }
}); });


Expand All @@ -292,8 +290,8 @@ test("should send the view, event and current Handlebars context to the action",
view.$('#edit').trigger('click'); view.$('#edit').trigger('click');


strictEqual(passedTarget, aTarget, "the action is called with the target as this"); strictEqual(passedTarget, aTarget, "the action is called with the target as this");
strictEqual(passedView, view, "the view passed is the view containing the action helper"); strictEqual(passedEvent.view, view, "the view passed is the view containing the action helper");
deepEqual(passedContext, aContext, "the context passed is the context surrounding the action helper"); deepEqual(passedEvent.context, aContext, "the context passed is the context surrounding the action helper");
equal(passedEvent.type, 'click', "the event passed is the event triggered for the action helper"); equal(passedEvent.type, 'click', "the event passed is the event triggered for the action helper");
}); });


Expand Down

0 comments on commit 657a266

Please sign in to comment.