Question
ui5的getEventBus底層是怎麼實作的?效率怎麼樣?
Answer
No special implementation, just normal subscriber - publisher design pattern.
Event subscriber gets EventBus instance via
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.