perf(animation): avoid ngzone with requestAnimationFrame (#19457)

* add patched zone for animations

* minify raf better
This commit is contained in:
Liam DeBeasi
2019-09-26 11:25:30 -04:00
committed by GitHub
parent eab0865fba
commit 8ca97ce42c
3 changed files with 28 additions and 11 deletions

View File

@ -2,6 +2,23 @@ import { EventEmitter } from '@stencil/core';
import { Side } from '../interface';
declare const __zone_symbol__requestAnimationFrame: any;
declare const requestAnimationFrame: any;
/**
* Patched version of requestAnimationFrame that avoids ngzone
* Use only when you know ngzone should not run
*/
export const raf = (h: any) => {
if (typeof __zone_symbol__requestAnimationFrame === 'function') {
return __zone_symbol__requestAnimationFrame(h);
}
if (typeof requestAnimationFrame === 'function') {
return requestAnimationFrame(h);
}
return setTimeout(h);
};
export const rIC = (callback: () => void) => {
if ('requestIdleCallback' in window) {
(window as any).requestIdleCallback(callback);