Turns an observable into a time travelable
version of itself.
It does this by creating a Subject to sink/stream the selected
historic index.
Then it it creates stateWithHistory$ which is just using
the scan operator to keep track of all emitted values.
A final index$ observable is created that only emits
index values that are within the bounds of the history
array's length.
A final state$ observable is created by combining
index$ and stateWithHistory$ to either select state
from the history array or return the active, current state
if the index is -1
The return value of this function is a thruple of:
0: The final state$ observable
1: A dispatch function for setting the selected index
2: The index$ observable emitting both the index and the maximum
Turns an observable into a time travelable version of itself.
It does this by creating a Subject to sink/stream the selected historic index.
Then it it creates
stateWithHistory$
which is just using thescan
operator to keep track of all emitted values.A final
index$
observable is created that only emits index values that are within the bounds of the history array's length.A final
state$
observable is created by combiningindex$
andstateWithHistory$
to either select state from the history array or return the active, current state if the index is-1
The return value of this function is a thruple of: 0: The final
state$
observable 1: A dispatch function for setting the selected index 2: Theindex$
observable emitting both the index and the maximum