RxJS allows combine streams in various ways. This lesson shows do you have a click stream and combine it with a store stream to use a value from the store inside a Reducer.
The logic is when we click the Recall button, it'll reset all the people's time to the current time.
First, bind the click event to recall$:
<button (click) ="recall$.next ()">Recall</button>New Subject ();
We get the latest time from the time Stroe:
Constructor (store:store) { This. Time = store.Select('Clock'); This. People = store.Select('people'); Observable.merge ( This. click$, This. seconds$, This. person$, This. recall$. Withlatestfrom ( This. Time, (_, y) = = y)//_: Means don ' t need to care on the first param which is this.recall$. Map (time) =({type:recall, payload:time}))) . Subscribe (Store.dispatch.bind (store))}
_: Is naming convention, it means, and don ' t care about the first value.
Last, we handle the action in reducer:
Case RECALL: return state.map (person) = {return { name:person.name, time : Payload }; })
-------------
[Angular 2] Using a Value from the Store in a Reducer