1 | // Type definitions for d3JS d3-timer module 3.0
|
2 | // Project: https://github.com/d3/d3-timer/, https://d3js.org/d3-timer
|
3 | // Definitions by: Tom Wanzek <https://github.com/tomwanzek>
|
4 | // Alex Ford <https://github.com/gustavderdrache>
|
5 | // Boris Yankov <https://github.com/borisyankov>
|
6 | // denisname <https://github.com/denisname>
|
7 | // Nathan Bierema <https://github.com/Methuselah96>
|
8 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
9 |
|
10 | // Last module patch version validated against: 3.0.1
|
11 |
|
12 | /**
|
13 | * Returns the current time as defined by performance.now if available, and Date.now if not.
|
14 | * The current time is updated at the start of a frame; it is thus consistent during the frame, and any timers scheduled during the same frame will be synchronized.
|
15 | * If this method is called outside of a frame, such as in response to a user event, the current time is calculated and then fixed until the next frame,
|
16 | * again ensuring consistent timing during event handling.
|
17 | */
|
18 | export function now(): number;
|
19 |
|
20 | export interface Timer {
|
21 | /**
|
22 | * Restart a timer with the specified callback and optional delay and time.
|
23 | * This is equivalent to stopping this timer and creating a new timer with the specified arguments,
|
24 | * although this timer retains the original invocation priority.
|
25 | *
|
26 | * @param callback A callback function to be invoked and passed in the apparent
|
27 | * elapsed time since the timer became active in milliseconds.
|
28 | * @param delay An optional numeric delay in milliseconds (default = 0) relative to time.
|
29 | * @param time An optional time in milliseconds relative to which the delay is calculated (default = now).
|
30 | */
|
31 | restart(callbackFn: (elapsed: number) => void, delay?: number, time?: number): void;
|
32 |
|
33 | /**
|
34 | * Stop the timer.
|
35 | */
|
36 | stop(): void;
|
37 | }
|
38 |
|
39 | /**
|
40 | * Schedules and returns a new timer, invoking the specified callback repeatedly until the timer is stopped.
|
41 | * The callback is passed the (apparent) elapsed time since the timer became active.
|
42 | *
|
43 | * @param callback A callback function to be invoked and passed in the apparent
|
44 | * elapsed time since the timer became active in milliseconds.
|
45 | * @param delay An optional numeric delay in milliseconds (default = 0) relative to time.
|
46 | * @param time An optional time in milliseconds relative to which the delay is calculated (default = now).
|
47 | */
|
48 | export function timer(callback: (elapsed: number) => void, delay?: number, time?: number): Timer;
|
49 |
|
50 | /**
|
51 | * Immediately invoke any eligible timer callbacks.
|
52 | */
|
53 | export function timerFlush(): void;
|
54 |
|
55 | /**
|
56 | * Schedules and returns a new timer, invoking the specified callback. The timer is stopped automatically
|
57 | * on its first callback. The callback is passed the (apparent) elapsed time since the timer became active.
|
58 | *
|
59 | * @param callback A callback function to be invoked and passed in the apparent
|
60 | * elapsed time since the timer became active in milliseconds.
|
61 | * @param delay An optional numeric delay in milliseconds (default = 0) relative to time.
|
62 | * @param time An optional time in milliseconds relative to which the delay is calculated (default = now).
|
63 | */
|
64 | export function timeout(callback: (elapsed: number) => void, delay?: number, time?: number): Timer;
|
65 |
|
66 | /**
|
67 | * Schedules and returns a new timer, invoking the specified callback repeatedly every 'delay' milliseconds
|
68 | * until the timer is stopped.
|
69 | * The callback is passed the (apparent) elapsed time since the timer became active.
|
70 | *
|
71 | * @param callback A callback function to be invoked and passed in the apparent
|
72 | * elapsed time since the timer became active in milliseconds.
|
73 | * @param delay An optional numeric delay in milliseconds between repeat invocations of the callback.
|
74 | * If not specified, the interval timer behaves like the regular timer.
|
75 | * @param time An optional time in milliseconds relative to which the initial delay is calculated (default = now).
|
76 | */
|
77 | export function interval(callback: (elapsed: number) => void, delay?: number, time?: number): Timer;
|