mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(util): add requestIdleCallback polyfill
This commit is contained in:
@@ -340,4 +340,12 @@ describe('util', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('requestIdleCallback polyfill', () => {
|
||||
|
||||
it('should return a value lazily', () => {
|
||||
expect(util.requestIonicCallback(() => { return 1; })).toEqual(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -179,6 +179,15 @@ function _assert(actual: any, reason: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
export function requestIonicCallback(functionToLazy: any) {
|
||||
if ('requestIdleCallback' in window) {
|
||||
return (window as any).requestIdleCallback(functionToLazy);
|
||||
} else {
|
||||
return setTimeout(functionToLazy, 500);
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
export { _assert as assert};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user