-
Notifications
You must be signed in to change notification settings - Fork 31
/
request-idle-callback.d.ts
53 lines (49 loc) · 1.93 KB
/
request-idle-callback.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
declare interface RequestIdleCallbackOptions {
/**
* A deadline by which the browser must call the given callback function.
* This value is given in milliseconds.
*/
timemout: number;
}
/**
* The `DOMHighResTimeStamp` type is a double and is used to store a time value.
* The value could be a discrete point in time or the difference in time between
* two discrete points in time. The unit is milliseconds and should be accurate
* to 5 µs (microseconds). However, if the browser is unable to provide a
* time value accurate to 5 microseconds (due, for example, to hardware or
* software constraints), the browser can represent the value as a time in milliseconds
* accurate to a millisecond.
*/
declare type DOMHighResStamp = number;
declare interface Deadline {
timeRemaining: () => DOMHighResStamp;
didTimout: boolean;
}
/**
* The `window.requestIdleCallback()` method queues a function to be called
* during a browser's idle periods. This enables developers to perform
* background and low priority work on the main event loop,
* without impacting latency-critical events such as animation and input response.
* Functions are generally called in first-in-first-out order
* unless the function's timeout is reached before the browser calls it.
* @return An unsigned long integer that can be used to cancel the callback using
* the `Window.cancelIdleCallback()` method.
*/
declare interface RequestIdleCallback {
(
/** A reference to a function that should be called in the near future. */
callback: (deadline: Deadline) => any,
/** Contains optional configuration parameters */
options?: RequestIdleCallbackOptions
): number;
}
/**
* The `Window.cancelIdleCallback()` enables you to cancel a callback
* previously scheduled with Window.requestIdleCallback.
*/
declare interface CancelIdleCallback {
/**
* The unsigned long integer returned by calling Window.requestIdleCallback.
*/
handle: number;
}