天天看點

UI5 EventBus

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”.

UI5 EventBus

The event registration is done based on channel id.

UI5 EventBus

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.

UI5 EventBus

When the event publisher has event to raise,

UI5 EventBus

it simply goes through the previously mentioned event registry mEventRegistery,

UI5 EventBus

and:

UI5 EventBus

this is how the event handler defined in application is called:

UI5 EventBus

regarding the performance, as you see this implementation is quite lean and no additional runtime overhead is there, performance should be quite good. 

ui5

繼續閱讀