Skip to content

Commit

Permalink
feat(mapTo): implement mapTo
Browse files Browse the repository at this point in the history
  • Loading branch information
TylorS authored and Andre Medeiros committed Mar 28, 2016
1 parent 9f1af1f commit f73bc8e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/operator/MapToOperator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {InternalListener} from '../InternalListener';
import {Operator} from '../Operator';
import {Stream} from '../Stream';
import {emptyListener} from '../utils/emptyListener';

export class Proxy<T, R> implements InternalListener<T> {
constructor(public out: Stream<R>,
public op: MapToOperator<T, R>) {
}

_n(t: T) {
this.out._n(this.op.projectedValue);
}

_e(err: any) {
this.out._e(err);
}

_c() {
this.out._c();
}
}

export class MapToOperator<T, R> implements Operator<T, R> {
public proxy: InternalListener<T> = emptyListener;

constructor(public projectedValue: R,
public ins: Stream<T>) {
}

_start(out: Stream<R>): void {
this.ins._add(this.proxy = new Proxy(out, this));
}

_stop(): void {
this.ins._remove(this.proxy);
}
}

0 comments on commit f73bc8e

Please sign in to comment.