欢迎各位兄弟 发布技术文章
这里的技术是共享的
https://rxjs-cn.github.io/learn-rxjs-operators/operators/transformation/mergemap.html
mapTo(value: any): Observable
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { interval } from 'rxjs';
import { mapTo } from 'rxjs/operators';
// 每2秒发出值
const source = interval(2000);
// 将所有发出值映射成同一个值
const example = source.pipe(mapTo('HELLO WORLD!'));
// 输出: 'HELLO WORLD!'...'HELLO WORLD!'...'HELLO WORLD!'...
const subscribe = example.subscribe(val => console.log(val));
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { fromEvent } from 'rxjs';
import { mapTo } from 'rxjs/operators';
// 发出每个页面点击
const source = fromEvent(document, 'click');
// 将所有发出值映射成同一个值
const example = source.pipe(mapTo('GOODBYE WORLD!'));
// 输出: (click)'GOODBYE WORLD!'...
const subscribe = example.subscribe(val => console.log(val));
mapTo - 官方文档
使用 mapTo 来改变行为 - John Linquist
转换操作符: map 和 mapTo - André Staltz
源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/mapTo.ts
来自 https://rxjs-cn.github.io/learn-rxjs-operators/operators/transformation/mapto.html