删除模型和集合
使用 Backbone.js:
当用户注销时删除一堆模型和集合是否正常?
这就是我计划在我的应用程序中执行的操作,以防止僵尸数据/绑定,但我不知道这是否是处理问题的最佳方法。
如果这是一个好的做法,我应该在清理时调用delete this
吗?
Using Backbone.js:
When a user logs out is it normal to delete a bunch of models and collections?
That's what I plan to do in my application to prevent zombie data/bindings but I dont know if it's the best way to handle things.
If this is a good practice should I just call delete this
on cleanup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要担心的僵尸来自于事件的绑定。我从观点的角度写了一篇关于此的文章: http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
在您的模型情况下,您应该先解除绑定,然后删除不需要的模型和集合。调用
delete everything
是确保事情真正消失的最佳方法。请务必首先取消与模型和集合事件的绑定,否则最终会得到指向未定义的绑定并导致异常。the zombies you need to worry about come from binding to events. i wrote a post about this from the perspective of views: http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
in your case with models, you should do the unbinding first and then delete the models and collections you don't need. calling
delete whatever
is the best way to ensure that things are truly gone. be sure to unbind from your model and collection events first, or you'll end up with bindings that point to undefined and cause exceptions.