如何设置条件,使第一次和第二次鼠标点击之间的延迟不超过 500 毫升
how to set a condition so that between the first and second mouse clicks there was a delay not > 500mls
我有一个定时器,所以它应该通过按下“等待”按钮来暂停。但是按钮点击有自己的条件。应该是 2 次点击,第一次和第二次点击之间的时间不得 >500 毫升。所以我需要优先使用 rxjs 运算符
const observable$ = interval(1000).pipe(mapTo(1));
const action$ = new Subject ();
const wait$ = action$.pipe(filter( action => action === false);
const timer$ = merge(wait$, start$)
.pipe(
startWith(true),
// if timer is paused return empty observable
switchMap(val => (val ? observable$ : EMPTY)),
scan((acc, curr) => (curr ? curr + acc : acc))
)
您可以尝试这样的操作:
buttonClicks.pipe(
bufferTime(500),
filter((clicks) => clicks.length > 1)
);
它在 500 毫秒内创建事件缓冲区 windows,然后在缓冲区中有多个点击事件时发出。
我有一个定时器,所以它应该通过按下“等待”按钮来暂停。但是按钮点击有自己的条件。应该是 2 次点击,第一次和第二次点击之间的时间不得 >500 毫升。所以我需要优先使用 rxjs 运算符
const observable$ = interval(1000).pipe(mapTo(1));
const action$ = new Subject ();
const wait$ = action$.pipe(filter( action => action === false);
const timer$ = merge(wait$, start$)
.pipe(
startWith(true),
// if timer is paused return empty observable
switchMap(val => (val ? observable$ : EMPTY)),
scan((acc, curr) => (curr ? curr + acc : acc))
)
您可以尝试这样的操作:
buttonClicks.pipe(
bufferTime(500),
filter((clicks) => clicks.length > 1)
);
它在 500 毫秒内创建事件缓冲区 windows,然后在缓冲区中有多个点击事件时发出。