javascript 事件总线架构 [英] javascript event bus architecture
问题描述
在 这个视频 20:50 (相应幻灯片),Nicholas Zakas 展示了我认为的一个事件总线架构.我不知道与 Bus 交互的调用是否应该是异步的?
第二个问题:如果调用是异步的,应该如何实现?
谢谢
In this video at 20:50 (corresponding slide), Nicholas Zakas presents what I think is an Event Bus architecture. What I don't know is whether the calls that interact with the Bus should be asynchronous or not?
The second question: if the calls are asynchronous, how should they be implemented?
Thank you
推荐答案
我相信它们确实是异步的.
I believe they are asynchronous indeed.
我的猜测是它们的实现方式是使用自定义 DOM 事件
.
My guess is that way they seem to be implemented is by using custom DOM events
.
这是一种在 javascript 中解耦的有用技术,您可以查看 jQuery 的 trigger 文档,寻找'custom' 字符串以查看如何触发自定义事件.
This is a useful technique for decoupling in javascript and you can check jQuery's trigger docs, look for the 'custom' string to see how to fire a custom event.
这篇关于javascript 事件总线架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!