官网介绍如下:
http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-repeatWhen
放珠宝图:
简而言之,就是 repeatWhen 操作符接收一个函数,这个函数返回一个新的 Observable ,暂且称之为 notifications。
那么当 Source Observable 进入 complete 或者 error 状态时,先要去看一看 notifications 的状态,如果 notifications 是 complete 或者 error 状态,那么就触发 Source Observable 相应的状态,否则就返回一个基于 Source Observable 的 Mirror 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