Is the startWith operator in RXJS really deprecated?

强颜欢笑 提交于 2020-08-06 07:38:16

问题


Since updating to RXJS version 6 my WebStorm editor has been complaining on some usages of startWith() that the operator is marked as deprecated.

You can see in the source code that the methods are marked deprecated:

  • Link to master (Harder link for future)

The problem for me is that the deprecated warning is not consistent. Sometimes it reports the method deprecated and other times it does not. While I can reproduce the warning in the below code examples. It seems to happen in my own source code randomly.

Not deprecated:

  of(false).pipe(startWith(true));

Is marked deprecated:

  const x: any = true;
  of(false).pipe(startWith(x));

So I am worried about these deprecated warnings. The deprecation message says to use scheduled() and concat() operators instead, but that feels like a more complicate alternative to an already handy operator like startWith().

So I'm kind of confused as to why it's deprecated, but also why it's only deprecated sometimes.


回答1:


No, it is not.

Currently there is only one active signature: startWith(...values)

Apart from this signature it has several overloads that accept scheduler: SchedulerLike as the latest parameter: startWith(...values, scheduler) and this functionality has been deprecated.

If you don't use scheduler with startWith you are fine.

If you do, then you need rewrite your code using scheduled function like they suggest in the comment beside depreciation annotation: scheduled([[a, b, c], source], scheduler).pipe(concatAll()).



来源:https://stackoverflow.com/questions/56571406/is-the-startwith-operator-in-rxjs-really-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!