Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Re-enable View#delegateEvents #47

Merged
merged 1 commit into from
May 2, 2012

Conversation

molily
Copy link
Member

@molily molily commented May 1, 2012

Re-enable Backbone’s delegateEvents so the events hash for registering DOM event handlers declaratively works again

Closes issue #42

…g DOM event handlers declaratively works again
@paulmillr
Copy link
Contributor

If events can be a function now, what about enhancing delegateEvents with @delegate features and removing the need in @delegate?

@molily
Copy link
Member Author

molily commented May 2, 2012

Good point! Since delegateEvents is very powerful (it can be called like delegate anywhere), yes, we can do that. I love removing code. ;) We definitely don’t have to reinvent the wheel if Backbone already provides all necessary means.

I’ve had a look into the moviepilot.com source code and 95% of the delegate calls can be replace by a declarative events hash. The other 5% are conditional calls which could be replaced by @delegateEvents 'click .foo': 'method' calls I think.

Actually I don’t remember why we introduced @delegate now that I realize how flexible delegateEvents is. I assume an older version of Backbone with which we started didn’t do provide what we needed. Also, the flexibility of delegateEvents isn’t well documented, so maybe I just read the docs instead of reading the source code directly. ;)

paulmillr added a commit that referenced this pull request May 2, 2012
@paulmillr paulmillr merged commit a6cacd5 into development May 2, 2012
@molily
Copy link
Member Author

molily commented May 6, 2012

I was wrong. delegateEvents is not usable for programatically adding handlers. It removes all handlers every time by calling undelegateEvents. Then it adds the handlers passed by parameter. If none were passed, it falls back to the events hash/function. It cannot be used to add a few handlers conditionally without removing and re-registering all others. :(

@molily
Copy link
Member Author

molily commented May 6, 2012

It’s not that bad: Since delegateEvents is called after initialize, one can create an events hash programatically in it.

But in general, I find it useful to have consistency with @delegate instead of weird workarounds which are be necessary in some cases if you use the delegateEvents/events approach.

@paulmillr
Copy link
Contributor

so, anyway, we can write 95% of events in a declarative way and other five percents with delegateEvents, right?

What five percents are it?

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

Successfully merging this pull request may close these issues.

None yet

2 participants