Permalink
Browse files

Stash view and context on event object in action handler

  • Loading branch information...
dgeb committed Feb 28, 2012
1 parent 31f6780 commit 657a2664347b9a4f0ef01a96ad2adc30ba51a0f0
@@ -12,10 +12,13 @@ ActionHelper.registerAction = function(actionName, eventName, target, view, cont
ActionHelper.registeredActions[actionId] = {
eventName: eventName,
handler: function(event) {
event.view = view;
event.context = context;

if ('function' === typeof target.send) {
return target.send(actionName, { view: view, event: event, context: context });
return target.send(actionName, { event: event });
} else {
return target[actionName].call(target, view, event, context);
return target[actionName].call(target, event);
}
}
};
@@ -272,11 +272,9 @@ test("should send the view, event and current Handlebars context to the action",
var passedContext;

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

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

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");
deepEqual(passedContext, aContext, "the context passed is the context surrounding the action helper");
strictEqual(passedEvent.view, view, "the view passed is the view containing 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");
});

0 comments on commit 657a266

Please sign in to comment.