我正在尝试使用redux-observable epic来测量2个动作的持续时间。
有一个相关的答案,但它在我的情况下并没有真正的帮助。 In redux-observable, how can I measure the epics duration time when running complete?
testeeEpic = action$ => action$.ofType('TEST_START', 'TEST_EMD')
.pipe(
// How to measure duration between 'TEST_START' and 'TEST_EMD'
)
/*
`TEST_START` can be dispatched multiple times before `TEST_EMD`,
duration between the lastest `TEST_START` and `TEST_EMD` is needed.
*/
如果有人可以提供帮助,将不胜感激。
尝试timeInterval
- 它测量两次排放之间的时间。
要测量第一个START
和下一个END
之间的时间:
.pipe(
distinctUntilChanged(),
timeInterval(),
filter(({ value }) => value !== START_EVENT),
map(({ interval }) => interval)
)
Timespan between first START and next END example。
UPDATE
要测量最新的START
和跟随END
之间的时间:
.pipe(
timeInterval(),
pairwise(),
filter(([first, second]) =>
first.value === START_EVENT
&& second.value === END_EVENT
),
map(([, second]) => second.interval)
)
Timespan between latest START and following END example。
希望这可以帮助