Skip to content

Commit

Permalink
feat(remember): implement RememeberProducer
Browse files Browse the repository at this point in the history
Adds initial implementation of .remember()
Simply creates a stream that will replay the last event.
  • Loading branch information
TylorS committed Feb 29, 2016
1 parent 9d15567 commit 7279ad8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/operator/RememberProducer.ts
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);
}
}

0 comments on commit 7279ad8

Please sign in to comment.