我使用RxJs
跟踪网页中的事件并通过缓冲区发送。
我在unload
事件上发出一个缓冲区,但是在事件触发后它就完成了,所以它从未被触发过。
有没有办法在unload
上生成与我的缓冲区相关的所有内容?
/* globals $ */
import { Observable } from 'rx-dom'
import { Load, Unload } from './events'
$(function () {
const load$ = (new Load()).observer$() // triggered on page load
const unload$ = (new Unload()).observer$() // triggered on page unload
const source$ = Observable.merge(load$, unload$)
const intervalBetween = 5000
const dummyStart$ = Observable.return({})
const bufferizeEvents$ = [submit$, unload$]
const opening$ = dummyStart$
.concat.apply(dummyStart$, bufferizeEvents$)
.flatMapLatest(x => Observable.timer(0, intervalBetween))
.skip(1)
const buffers$ = source$.buffer(opening$)
buffers$.subscribe(buffer => {
if (buffer.length) {
// some ajax call
// this is never reached on page unload
}
})
})