Hi,
This is very helpful service.
I think the following changes will make it even better in term of the performance of the applicaiton using this service:
Running startWatching outside Angular zone.
Debouncing the idleSubscription
constructor(private zone: NgZone) {
}
public startWatching(timeOutSeconds): Observable<any> {
this.zone.runOutsideAngular(() => {
this.idle$ = merge(
fromEvent(document, 'mousemove'),
fromEvent(document, 'click'),
fromEvent(document, 'mousedown'),
fromEvent(document, 'keypress'),
fromEvent(document, 'DOMMouseScroll'),
fromEvent(document, 'mousewheel'),
fromEvent(document, 'touchmove'),
fromEvent(document, 'MSPointerMove'),
fromEvent(window, 'mousemove'),
fromEvent(window, 'resize'),
);
this.timeOutMilliSeconds = timeOutSeconds * 1000;
this.idleSubscription = this.idle$
.pipe(debounceTime(500)) // or maybe any number smaller than the timeout value
.subscribe((res) => {
this.resetTimer();
});
this.startTimer();
});
return this.expired$;
}
Hi, This is very helpful service. I think the following changes will make it even better in term of the performance of the applicaiton using this service: