.map(ball => makeSquare(ball))
map( ): <R> {
const = this;
return new ( =>
.subscribe(x =>
.next( (x))
);
}
project:(T) => R project
source
source
sink
sink
Observable
Observable
5. Operator logic
1. Operator Arguments
2. Source Observable
3. Destination Observer
4. Result Observable
flatMap<T, R>(
project:(value: T) => Observable<R>
): Observable<R>
lift<T, R>(
project:(Observer<R>) => Observer<T>
): Observable<R>
class Observable {
map(project) {
return this.lift(
new MapOperator(project));
}
}
class MapOperator {
constructor(project) {}
call(sink, source) {
return source.subscribe(
new MapObserver(sink, this.project));
}
}
class MapObserver {
constructor(sink, project) {}
next(x) {
this.sink.next(this.project(x));
}
}
1. Predictable shapes
2. Ensures hot paths
are taken
3. Can merge Observer +
Subscription into one
4. Customize result
Observable type
of( , , , )
.map(makeSquare)
.filter(isGreen)
source
operator
of(...)
source
operator