As a beginner in rxjs and declarative programming, please forgive me if this question seems naive!
I am working with Typescript, attempting to create functionality similar to that of a digital register. I have two input boolean observables, A and B, as well as an output register O (also boolean).
Specifications:
- O should initially be set to "false"
- When B transitions from FALSE to TRUE, O should be updated with the current value of A
- In all other cases, the current value of O should remain unchanged
My goal is to store the value of A when B becomes true, so that I can use it when B goes false again.
I came across this question, but I'm struggling to apply its answer to my specific scenario.
I believe I can utilize pairwise() on B to detect the transition from FALSE to TRUE (previousValue === false && currentValue === true), along with withLatestFrom to access the current value of A and update O accordingly.
However, I'm unsure how to retain/re-emit the current value of O in all other situations. It appears that there is no way, within a pipe operator defining Observable O, to reference its existing value.