UNPKG

@exmg/lit-base

Version:
143 lines (142 loc) 4.54 kB
/** @license Copyright (c) 2017 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ export interface AsyncInterface { run: (fn: Function, delay?: number) => number; cancel: (handle: number) => void; } /** * Not defined in the TypeScript DOM library. * See https://developer.mozilla.org/en-US/docs/Web/API/IdleDeadline */ export interface IdleDeadline { didTimeout: boolean; timeRemaining(): number; } /** * Async interface wrapper around `setTimeout`. * * @namespace * @summary Async interface wrapper around `setTimeout`. */ declare const timeOut: { /** * Returns a sub-module with the async interface providing the provided * delay. * * @memberof timeOut * @param {number=} delay Time to wait before calling callbacks in ms * @return {!AsyncInterface} An async timeout interface */ after(delay: number): { run(fn: any): number; cancel(handle: any): void; }; /** * Enqueues a function called in the next task. * * @memberof timeOut * @param {!Function} fn Callback to run * @param {number=} delay Delay in milliseconds * @return {number} Handle used for canceling task */ run(fn: any, delay?: number): number; /** * Cancels a previously enqueued `timeOut` callback. * * @memberof timeOut * @param {number} handle Handle returned from `run` of callback to cancel * @return {void} */ cancel(handle: any): void; }; export { timeOut }; /** * Async interface wrapper around `requestAnimationFrame`. * * @namespace * @summary Async interface wrapper around `requestAnimationFrame`. */ declare const animationFrame: { /** * Enqueues a function called at `requestAnimationFrame` timing. * * @memberof animationFrame * @param {function(number):void} fn Callback to run * @return {number} Handle used for canceling task */ run(fn: any): number; /** * Cancels a previously enqueued `animationFrame` callback. * * @memberof animationFrame * @param {number} handle Handle returned from `run` of callback to cancel * @return {void} */ cancel(handle: number): void; }; export { animationFrame }; /** * Async interface wrapper around `requestIdleCallback`. Falls back to * `setTimeout` on browsers that do not support `requestIdleCallback`. * * @namespace * @summary Async interface wrapper around `requestIdleCallback`. */ declare const idlePeriod: { /** * Enqueues a function called at `requestIdleCallback` timing. * * @memberof idlePeriod * @param {function(!IdleDeadline):void} fn Callback to run * @return {number} Handle used for canceling task */ run(fn: any): number; /** * Cancels a previously enqueued `idlePeriod` callback. * * @memberof idlePeriod * @param {number} handle Handle returned from `run` of callback to cancel * @return {void} */ cancel(handle: any): void; }; export { idlePeriod }; /** * Async interface for enqueuing callbacks that run at microtask timing. * * Note that microtask timing is achieved via a single `MutationObserver`, * and thus callbacks enqueued with this API will all run in a single * batch, and not interleaved with other microtasks such as promises. * Promises are avoided as an implementation choice for the time being * due to Safari bugs that cause Promises to lack microtask guarantees. * * @namespace * @summary Async interface for enqueuing callbacks that run at microtask * timing. */ declare const microTask: { /** * Enqueues a function called at microtask timing. * * @memberof microTask * @param {!Function=} callback Callback to run * @return {number} Handle used for canceling task */ run(callback: any): number; /** * Cancels a previously enqueued `microTask` callback. * * @memberof microTask * @param {number} handle Handle returned from `run` of callback to cancel * @return {void} */ cancel(handle: any): void; }; export { microTask };