skipWhile

签名: skipWhile(predicate: Function): Observable

跳过源 observable 发出的值,直到提供的表达式结果为 false 。

skipWhile - 图1

示例

示例 1: 当值小于阈值的时候跳过

( jsBin |
jsFiddle )

  1. import { interval } from 'rxjs/observable/interval';
  2. import { skipWhile } from 'rxjs/operators';
  3. // 每1秒发出值
  4. const source = interval(1000);
  5. // 当源 observable 发出的值小于5的时候,则跳过该值
  6. const example = source.pipe(skipWhile(val => val < 5));
  7. // 输出: 5...6...7...8........
  8. const subscribe = example.subscribe(val => console.log(val));

其他资源


:file_folder: 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/skipWhile.ts