-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(remember): implement RememeberProducer
Adds initial implementation of .remember() Simply creates a stream that will replay the last event.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {Observer} from '../Observer'; | ||
import {Producer} from '../Producer'; | ||
import {Stream} from '../Stream'; | ||
import {emptyObserver} from '../utils/emptyObserver'; | ||
|
||
export class Proxy<T> implements Observer<T> { | ||
constructor(public out: Stream<T>, | ||
public p: RememberProducer<T>) { | ||
} | ||
|
||
next(t: T) { | ||
this.out.next(t); | ||
this.out.value = t; | ||
} | ||
|
||
error(err: any) { | ||
this.out.error(err); | ||
} | ||
|
||
end() { | ||
this.out.end(); | ||
} | ||
} | ||
|
||
export class RememberProducer<T> implements Producer<T> { | ||
public proxy: Observer<T> = emptyObserver; | ||
public value: any; | ||
|
||
constructor(public ins: Stream<T>) { | ||
} | ||
|
||
start(out: Stream<T>): void { | ||
this.ins.subscribe(this.proxy = new Proxy(out, this)); | ||
} | ||
|
||
stop(): void { | ||
this.ins.unsubscribe(this.proxy); | ||
} | ||
} |