简体   繁体   English

维护 PUB/SUB 通信

[英]Maintain PUB/SUB communication

What is the best practise to maintain complex structure using Pub/Sub to communicate between modules?使用 Pub/Sub 维护复杂结构以在模块之间进行通信的最佳实践是什么?

I finished up my last project with a lot of module that are nicely decoupled (maybe even “overdecoupled”).我完成了我的最后一个项目,其中有很多模块很好地解耦(甚至可能是“过度解耦”)。 But if want to debug something or change event subscriptions and publishes, a lot of CTRL + F is involved to find all code parts interrested in specific event.但是,如果要调试某些内容或更改事件订阅和发布,则需要使用大量CTRL + F来查找与特定事件相关的所有代码部分。 Is there any pattern for better event based communication management?是否有更好的基于事件的通信管理模式? I used Marionette and its EventAggregator as pub/sub.我使用 Marionette 及其EventAggregator作为发布/ EventAggregator

You are describing the exact use case for the RequestResponse object.您正在描述RequestResponse对象的确切用例。

https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.requestresponse.md https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.requestresponse.md

Handler:处理程序:

var App = new Marionette.Application();

App.reqres.setHandler("foo", function(bar){
  return bar + "-quux";
});

Request:要求:

App.request("foo", "baz"); // => returns "baz-quux"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM