Angular app that is running without NgZone. Triggering change-detection happens like this:
merge(
fromEvent(document, 'click'),
fromEvent(document, 'mousemove'),
fromEvent(document, 'keydown'),
fromEvent(document, 'scroll'),
fromEvent(document, 'touchstart'),
fromEvent(document, 'touchend'),
this.actions$,
this.contentChangesSubject.asObservable()
).pipe(
debounceTime(20)
).subscribe(_ => this.cdRef.detectChanges());
And in the main.ts
file, the app is bootstrapped like this:
platformBrowserDynamic()
.bootstrapModule(AppModule, {
ngZone: 'noop' // <-- this line tells Angular to not use NgZone
})
.catch(err => console.error(err));
And make sure to remove the import of zone.js from polyfills.ts
and environment.ts
.
For me,
debounceTime(20)
was randomly chosen. Anyone has a good idea how to determine the right amount of time for debouncing?