Question
ui5的getEventBus底层是怎么实现的?效率怎么样?
Answer
No special implementation, just normal subscriber - publisher design pattern.
Event subscriber gets EventBus instance via
sap.ui.getCore().getEventBus()
Subscriber code uses API subscribe to register the event handler provided by application with a given event.
In my example, my event handler is function onOrderApproved, and the event I would like to listen to is “OrderApproved”.
The event registration is done based on channel id. In EventBus singleton instance there is a central repository mEventRegistery which is actually a map: key is event id, value is an array containing all listeners for this event. When the event publisher has event to raise, it simply goes through the previously mentioned event registry mEventRegistery, and: this is how the event handler defined in application is called: regarding the performance, as you see this implementation is quite lean and no additional runtime overhead is there, performance should be quite good. 要获取更多Jerry的原创文章,请关注公众号"汪子熙":
本文同步分享在 博客“汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。