Closed vitch closed 11 years ago
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.
Cool - let me know if you have any questions. It seems to be working integrated into our (much) bigger project too :D
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.
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.
Cool stuff! Would love to hear back on the new inversion of control mechanism for Geppetto and Marionette.
@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!
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.
@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...
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...