-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
6,552 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// <reference lib="dom" /> | ||
|
||
export interface CancelCallback { | ||
(requestId: number): void; | ||
} | ||
|
||
interface IntervalometerReturnValue { | ||
start: VoidFunction; | ||
stop: VoidFunction; | ||
} | ||
|
||
/** | ||
* @param callback A callback that will be called. | ||
* @param request A window's requestAnimationFrame or setTimeout. | ||
* @param cancel A callback that will cancel the given intervalometer. Typically a window's cancelAnimationFrame or clearTimeout. | ||
* @param millis Time in milliseconds. | ||
*/ | ||
export function intervalometer( | ||
callback: VoidFunction, | ||
request: typeof requestAnimationFrame | typeof setTimeout, | ||
cancel: CancelCallback, | ||
millis?: number | ||
): IntervalometerReturnValue; | ||
|
||
/** | ||
* A time-based intervalometer. | ||
* | ||
* @param callback A callback that will be invoked after the given time-frame. | ||
* @param timeInMillis Time in milliseconds. | ||
*/ | ||
export function timerIntervalometer( | ||
callback: VoidFunction, | ||
timeInMillis: number | ||
): IntervalometerReturnValue; | ||
|
||
/** | ||
* A frame-based intervalometer. It uses requestAnimationFrame and calls the provided callback at every frame. | ||
* Ideal for animations. | ||
* | ||
* @param callback A callback that will be called on each animation frame. | ||
*/ | ||
export function frameIntervalometer( | ||
callback: VoidFunction | ||
): IntervalometerReturnValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable import/named */ | ||
|
||
import {expectType} from 'tsd'; | ||
import {intervalometer, frameIntervalometer, timerIntervalometer, IntervalometerReturnValue} from '.' | ||
|
||
expectType<IntervalometerReturnValue>(intervalometer(() => { }, setTimeout, () => { }, 1)); | ||
expectType<IntervalometerReturnValue>(frameIntervalometer(() => { })); | ||
expectType<IntervalometerReturnValue>(timerIntervalometer(() => { }, 1000)); |
Oops, something went wrong.