使用startWith时,RxJS跳过去抖动

und*_*ned 3 rxjs angular

我有一个使用startWith运算符的流debounceTime.我希望第一个值跳过debounceTime并立即启动.我该怎么做?

control.valueChanges
    .pipe(
      startWith(control.value), <=== this needs to skip debounce
      debounceTime(200),
      map(...),
    );
Run Code Online (Sandbox Code Playgroud)

mar*_*tin 7

只需切换运算符的顺序并startWith在之后使用debounceTime.

control.valueChanges.pipe(
  debounceTime(200),
  startWith(control.value),
  map(...),
);
Run Code Online (Sandbox Code Playgroud)

  • 运营商的秩序很重要.当您在链的末尾订阅时,运算符之间的内部订阅将自下而上创建.因此,当创建对`startWith`的订阅时,它会在订阅它上面的运算符之前立即发出`control.value`. (2认同)