SOURCE

/**
 * rxjs version 6.5.3
 * github: https://rxjs-cn.github.io/learn-rxjs-operators/operators/combination/startwith.html
 * 本样例使用 cdn 的方式引入rxjs
 */
const { startWith } = rxjs.operators;
const { of, from } = rxjs;

// startWith  
// 设置流的初始值

// 样例1
// 使用 of 创建数据源
const source = of(1, 2, 3);
// 在 pipe 管道中,以 3 开始
// 输出:3,1,2,3
source.pipe(startWith(3)).subscribe(n => console.log(n));

// 使用 from 创建数据源
const source2 = from([1, 2, 3]);
// 输出 4,1,2,3
source2.pipe(startWith(4)).subscribe(n => console.log(n));

// 样例2 使用多个值 作为初始值
const source3 = of(1, 'hello world', 'john snow');
source3.pipe(startWith(-3, -2, -1, 0)).subscribe(n => console.log(n));
console 命令行工具 X clear

                    
>
console