-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Always delegate in #setElement. #3060
Conversation
Another question to ask would be, why would anyone want to not redelegate events when setting a new |
👍 |
I think because you might want to go and trigger an event during But if you think it's clearly better — |
Hmm...you mean you might want to trigger an event before attaching listeners? I don't quite follow. |
Sorry — you're right. I was confused. |
Always delegate in #setElement.
This may be very minor or even a non-issue... certainly less of an issue until the next backbone release. Backbone.View.delegateEvents is for explicitly setting up events on the.$el and this is even more evident with this PR for an upcoming release: jashkenas/backbone#3060 Marionette Entity events don't need to be re-setup if the $el changes. Really it seems they may need only be bound in the constructor and cleaned up, as they will be anyways, on destroy. Then if you needed to dynamically change collectionEvents or modelEvents for some reason, you'd use Marionette.View.bindEntityEvents However a change like this would be breaking for anyone currently using delegateEvents as a reset for if changes are made to modelEvents or collectionEvents.
Document delegateEvents change from #3060
Might be worth reconsidering this one, there are now 6 bug reports (#3166, #3256, #3704, #3620, marionettejs/backbone.marionette#2605, marionettejs/backbone.marionette#2628) that I know of from users about modifying the |
This seems like something that you should've been doing in the first place. Not sure why we'd roll it back. |
Just using libraries I've written on top of Backbone as an example, I always do binding after calling Yes, it can be solved by using a function instead, but Backbone's encouraged extend using objects doesn't make it obvious. Modifying in an |
But why? |
I think that's fighting against a common usage. It's not just new devs that are falling into it, I do it as well.
But these aren't waiting for a render to bind new events handlers. It's about treating
We've encouraged this usage pattern by providing an As a side note, library authors aren't able to provide this same functionality. You can either bind this like |
Ok, crazy question. Why do we delegate events after calling
View#initialize
instead of before? The test suite passes either way so I have only conjecture. Here are a couple:el
in#initialize
- This is probably ill advised but changing this doesn't alter behavior. Events would just be delegated twice.#events
in#initialize
- I suppose you could, but I would say this is also ill advised. Regardless, you could do it in the constructor if you had to.Anything I missed? This allows us to do away with the
delegate
argument tosetElement
, which is a clear win I think.