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

Already on GitHub? Sign in to your account

Stash view and context on event object in action handler #544

Merged
merged 2 commits into from Feb 28, 2012

Conversation

Projects
None yet
3 participants
Owner

dgeb commented Feb 28, 2012

Event handlers should be consistent, whether they're set up as standard event listeners for views or they're handlers for action helpers.

By stashing the view and context on the event object, we can pass event as the one and only argument to handlers for action helpers. This meta-data might prove useful if, say, a different view has been targeted than the current one.

For instance, the following action helper:

<a href="#" {{action "editRow" target="parentView"}}>Edit</a>

...could have this handler:

App.ListingView = Ember.View.extend({
  templateName: 'listing',

  editRow: function(event) {
    event.view.set('isEditing', true);
  }
});

I think this is much easier to remember and use than the order of the parameters currently passed: view, event, context.

This seems good, but can you just pass the event in here?

return target.send(actionName, event);

Now there's no reason to send it wrapped in an object.

Agreed.

Owner

dgeb replied Feb 28, 2012

Indeed - that was silly. Thanks for the correction.

Owner

dgeb commented Feb 28, 2012

@devinus @ebryn thanks for pointing that out - I just updated the PR.

Owner

ebryn commented Feb 28, 2012

Looks good. Thanks!

ebryn added a commit that referenced this pull request Feb 28, 2012

Merge pull request #544 from dgeb/action-handler-event-mods
Stash view and context on event object in action handler

@ebryn ebryn merged commit e9ca2e2 into emberjs:master Feb 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment