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

[Proposal] Call the bind and unbind method in view hooks instead of route hooks/events #5

Open
visheshjoshi opened this issue Mar 17, 2015 · 2 comments

Comments

@visheshjoshi
Copy link

I also wanted to suggest, doing the binding and unbinding as a part of the 'didInsertElement' hook and the 'willDestroyElement' hook of Ember.view.

Reasoning:
Mousetrap relies on capturing a DOM element and acting on it. Having the bindings on activate of a route might cause this to fail sometimes in case the DOM has not been rendered yet.

Users can be suggested to override the Ember.view class in their applications main view.
The 'didInsertElement' of the applications main view will be called after all the other views have been rendered.

Let me know what you feel about that. If you agree, I can send a PR with the required changes

@ursm
Copy link
Member

ursm commented Mar 31, 2015

Sorry for the late reply.

A view is lack of ability to fire an action (on its own), so we used a router for now. For example:

FooRoute = Ember.Route.extend MousetrapRoute,
  actions:
    awesomeAction: ->
     # some goodness

  shortcuts:
    awesomeShortcut: mousetrap 'a', ->
      @send 'awesomeAction'

But I think your proposal is also proper in some situations (e.g. handler does DOM operation mainly).

I think it's better to make different mixin, not to replace MousetrapRoute. What do you think?

@visheshjoshi
Copy link
Author

Sounds good to me.

Here is the PR. Please take a look and merge : #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants