mapTo
연산자(operator) 정의: mapTo(value: any): Observable
Map emissions to constant value.
Examples
Example 1: Map every emission to string
//emit value every two seconds
const source = Rx.Observable.interval(2000);
//map all emissions to one value
const example = source.mapTo('HELLO WORLD!');
//output: 'HELLO WORLD!'...'HELLO WORLD!'...'HELLO WORLD!'...
const subscribe = example.subscribe(val => console.log(val));
Example 2: Mapping clicks to string
//emit every click on document
const source = Rx.Observable.fromEvent(document, 'click');
//map all emissions to one value
const example = source.mapTo('GOODBYE WORLD!');
//output: (click)'GOODBYE WORLD!'...
const subscribe = example.subscribe(val => console.log(val));
Related Recipes
Additional Resources
- mapTo - Official docs
- Changing behavior with mapTo - John Linquist
- Transformation operator: map and mapTo - André Staltz
Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/operator/mapTo.ts