Issue
I have a timer, so it should take a pause by "wait" button press. But button click has own condition. It should be 2 clicks and time between first and second clicks must be not >500mls. So i need to use rxjs operators preferably
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))
)
Solution
You could try something like this:
buttonClicks.pipe(
bufferTime(500),
filter((clicks) => clicks.length > 1)
);
It creates buffers of events in 500ms windows and then emits when more than one click event is in a buffer.
Answered By - NickL
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.