ngrx Effect学习笔记
SAP Spartacus的connector通過NgRx的Effect從SAP Commerce Cloud后臺取數據。
官網地址:https://ngrx.io/guide/effects
Effects的五大要點
Effects are injectable service classes with distinct parts:
(1) An injectable Actions service that provides an observable stream of all actions dispatched after the latest state has been reduced.
監聽currency和language change:
每個injectable Effects都有一個action service actions$,在store最新的狀態被reduce之后,能夠dispatch一個observable stream.
(2) Metadata is attached to the observable streams using the createEffect function. The metadata is used to register the streams that are subscribed to the store. Any action returned from the effect stream is then dispatched back to the Store.
使用createEffect將Metadata添加到observable streams上去。Metadata的作用是將streams注冊到store上去。從Effect stream返回的action會重新dispatch到store中去。
(3) Actions are filtered using a pipeable ofType operator. The ofType operator takes one or more action types as arguments to filter on which actions to act upon.
Actions通過ofType操作符進行過濾。ofType操作符接受一個或多個Action type作為輸入參數,過濾某個effect應該響應哪一個action.
(4) Effects are subscribed to the Store observable.
Effects訂閱到store Observable上面。
(5) Services are injected into effects to interact with external APIs and handle streams.
服務注冊到effects里,同外部API交互。
關于Observable真正開始工作的時間點
官網提到:
This means that calling subscribe is actually the moment when Observable starts its work, not when it is created
調用Observable的subscribe方法,才是Observable真正開始工作的時間點,而不是它被創建的時候。
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的ngrx Effect学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 侍魂胧月传说可以自由交易吗
- 下一篇: SAP Spartacus里的登录tok