Rxjs 操作符之 repeatWhen

官网介绍如下:
http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-repeatWhen

放珠宝图:
Rxjs 操作符之 repeatWhen

简而言之,就是 repeatWhen 操作符接收一个函数,这个函数返回一个新的 Observable ,暂且称之为 notifications

那么当 Source Observable 进入 complete 或者 error 状态时,先要去看一看 notifications 的状态,如果 notificationscomplete 或者 error 状态,那么就触发 Source Observable 相应的状态,否则就返回一个基于 Source ObservableMirror Observable,以此往复。

注意:

这里需要注意的是,如果 notifications 进入 complete 状态,而 Source Observable 还未进入 complete 状态,那么会一直等待 Source Observable 进入 complete 状态后将整个流结束掉。

早期版本这里有个 bug,notifications 进入 complete 之后,会直接将 Source Observable 也置为 complete
参见:https://github.com/ReactiveX/rxjs/pull/2209

例子:

https://codepen.io/xusheng/pen/KvoJop?editors=1012