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

Update to work with marionette 1.0.0rc3 #8

Closed
wants to merge 8 commits into from

Conversation

vitch
Copy link

@vitch vitch commented Jan 24, 2013

I've just updated marionette on a project using Geppetto and some things broke. Mostly because Marionette has now removed EventBinder (in favour of the listenTo methods now in Backbone). I've tried fixing them here and it seems to be working for the tests and examples in this project. Integrating it into our project now - I'll let you know how it goes there...

@geekdave
Copy link
Contributor

Thanks so much for this, Kevin! This has been on my todo list ever since the new version of Backbone was released. I'll give it a whirl today and let you know how it goes for me.

@vitch
Copy link
Author

vitch commented Jan 25, 2013

Cool - let me know if you have any questions. It seems to be working integrated into our (much) bigger project too :D

Because Marionette.addEventBinder overwrites the toListen method to automatically _.bind the called method to a context then we can't pass the function in as the third argument to stopListening. This change means that things work as expected BUT it's not really safe. If the same object registered two different listeners to the same event then they would both be unsubscribed by this call rather than just the one we wanted to unsubscribe.

I'm not sure that the proper solution is because Marionette doesn't allow expose the wrapped function. Any ideas?
@vitch
Copy link
Author

vitch commented Jan 25, 2013

Actually, please see the commit message on the added commit. The automatic cleaning up wasn't working quite as expected. I've put a workaround in place but I don't think it's the ideal solution and am interested in any improvements you can make.

@geekdave
Copy link
Contributor

Yeah I tried this out yesterday and found that I was getting zombie views, and events not properly getting cleaned up. The solution I came up with is to embrace the "inversion of control" mechanism for event listening, introduced in the new Backbone API. Instead of Geppetto keeping track of listeners, we delegate to the view's built-in "listenTo" method and let the views keep track. When views are closed, their events are cleaned up. If a non-view wants to listen to a context, it can use Marionette.addEventBinder() to "mix-in" the listenTo method into itself. I'll have some code published shortly to illustrate this.

@pheuter
Copy link
Contributor

pheuter commented Jan 25, 2013

Cool stuff! Would love to hear back on the new inversion of control mechanism for Geppetto and Marionette.

@geekdave geekdave closed this in db0bf54 Jan 25, 2013
@geekdave
Copy link
Contributor

@vitch: I wound up removing most of the code in listen() and delegating to Backbone's listenTo(). Let me know what you think. The new unit tests I added should illustrate the idea. Your pull request was very helpful, and I wouldn't have been able to get these changes live anytime soon without you. So thanks! I gave you a little shout-out in the version history in the README. :)

@pheuter: Check out the changes and the updates to the README. Would love to hear your feedback as well!

@pheuter
Copy link
Contributor

pheuter commented Jan 25, 2013

Implemented the new changes in my Marionette.rc-3 / Backbone 0.9.10 codebase, things seem to be looking good! Thanks a lot @vitch and @geekdave for getting this through, it's really great to see Geppetto being maintained.

@vitch
Copy link
Author

vitch commented Jan 29, 2013

@geekdave - nice one :) I've integrated this into our codebase and it seems to be working great. The new approach makes much more sense too - nice one. And thanks for Geppetto btw - it's really helped keep our growing codebase rational...

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

Successfully merging this pull request may close these issues.

3 participants