gpt4 book ai didi

javascript - 移除 Marionette EventAggregator : really necessary to prevent leaks?

转载 作者:行者123 更新时间:2023-11-30 12:55:17 25 4
gpt4 key购买 nike

我正在阅读 Backbone.Wreqr 中的 EventAggregator 文档.它可以像下面这样使用。

MyApp.vent.trigger("some:namespaced:event");

MyApp.vent.on("some:namespaced:event", function(){
// ...
});

我不明白,一旦在 View 中设置了一个处理程序,我是否需要将其删除,或者 Marionette 会在 onClose 方法或其他地方为我做这件事?如果我需要删除它,我可以遵循的最佳方法是什么?是否有必要只关闭 该事件?同样适用于 Commands使用 removeHandler?

你能给我指出正确的方向吗?

最佳答案

这取决于你的情况。如果您不想监听某些事件,当模块不工作时,您可以订阅模块“停止”事件并为所有必要的事件执行关闭。

module.on("stop", function(){
App.vent.off(someMethods);
});

像往常一样, View 不使用全局事件聚合。但是如果你使用,你应该使用

this.listenTo( App.vent, "someEvent", function(){...} )

然后 Marionette 删除此处理程序。

关于javascript - 移除 Marionette EventAggregator : really necessary to prevent leaks?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19379117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com