天天看點

Subject 在 SAP Spartacus Popover Component 中的應用

Subject 是 Rxjs 裡的一個工具對象。

Subject 在 SAP Spartacus Popover Component 中的應用
Subject 在 SAP Spartacus Popover Component 中的應用
Subject 在 SAP Spartacus Popover Component 中的應用
Subject 在 SAP Spartacus Popover Component 中的應用
Subject 在 SAP Spartacus Popover Component 中的應用

在 close 事件處理函數裡,通過 Subject 向其監聽者廣播 CLOSE_BUTTON_CLICK 或者 CLOSE_BUTTON_KEYDOWN 事件。

Subject 在 SAP Spartacus Popover Component 中的應用

在 Popover Directive 裡定義了所有能夠觸發 Popover Component 關掉的事件,如上圖所示。

Popover Directive 是這些事件的監聽者。

Subject 在 SAP Spartacus Popover Component 中的應用

這裡有兩個問題:

handlePopverEvents 什麼時候被誰調用?

為什麼是 Directive 的 close 函數負責關閉 Popover Component?

對于第一個問題,這裡能看出端倪了:Popover Directive 的 eventSubject 負責監聽事件,然後這個 eventSubject 執行個體賦給 Component 執行個體,後者負責發送事件:

Subject 在 SAP Spartacus Popover Component 中的應用
Subject 在 SAP Spartacus Popover Component 中的應用
Subject 在 SAP Spartacus Popover Component 中的應用

繼續閱讀