chore(util): add requestIdleCallback polyfill

This commit is contained in:
jgw96
2017-03-07 16:12:02 -06:00
parent 5a4f8b9b5d
commit 8c75c214d7
2 changed files with 17 additions and 0 deletions

View File

@@ -340,4 +340,12 @@ describe('util', () => {
});
describe('requestIdleCallback polyfill', () => {
it('should return a value lazily', () => {
expect(util.requestIonicCallback(() => { return 1; })).toEqual(1);
});
});
});

View File

@@ -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};