从Marionette.EventAggregator和Marionette.EventBinder中的文档中,代码完全相同。我想我不知道有什么不同,它是什么?何时使用它们?
答案 0 :(得分:4)
主要区别在于意图。在这些文章中解释了EventAggregator的意图:
http://martinfowler.com/eaaDev/EventAggregator.html
http://codebetter.com/jeremymiller/2009/07/22/braindump-on-the-event-aggregator-pattern/
EventBinder的目的是管理事件绑定中的依赖关系,如Johnny Oshika在此首先描述的那样:Backbone.js : repopulate or recreate the view?
...
继续使用Marionette和Backbone v0.9.9,EventBinder现在已经过时,因为Backbone.Events现在包含listenTo
和stopListening
方法。 EventAggregator
正在接管Backbone.Events未涵盖的任何内容。不过,这适用于Marionette v1.0-rc3及更高版本。如果您仍在使用Marionette v1.0-rc2或之前版本,则仍需要EventBinder。