MCPcopy
hub / github.com/Splidejs/splide / RequestInterval

Function RequestInterval

src/js/constructors/RequestInterval/RequestInterval.ts:28–149  ·  view source on GitHub ↗
(
  interval: number,
  onInterval: () => void,
  onUpdate?: ( rate: number ) => void,
  limit?: number
)

Source from the content-addressed store, hash-verified

26 * @param limit - Optional. Limits the number of interval.
27 */
28export function RequestInterval(
29 interval: number,
30 onInterval: () => void,
31 onUpdate?: ( rate: number ) => void,
32 limit?: number
33): RequestIntervalInterface {
34 const { now } = Date;
35
36 /**
37 * The time when the interval starts.
38 */
39 let startTime: number;
40
41 /**
42 * The current progress rate.
43 */
44 let rate = 0;
45
46 /**
47 * The animation frame ID.
48 */
49 let id: number;
50
51 /**
52 * Indicates whether the interval is currently paused or not.
53 */
54 let paused = true;
55
56 /**
57 * The loop count. This only works when the `limit` argument is provided.
58 */
59 let count = 0;
60
61 /**
62 * The update function called on every animation frame.
63 */
64 function update(): void {
65 if ( ! paused ) {
66 rate = interval ? min( ( now() - startTime ) / interval, 1 ) : 1;
67 onUpdate && onUpdate( rate );
68
69 if ( rate >= 1 ) {
70 onInterval();
71 startTime = now();
72
73 if ( limit && ++count >= limit ) {
74 return pause();
75 }
76 }
77
78 id = raf( update );
79 }
80 }
81
82 /**
83 * Starts the interval.
84 *
85 * @param resume - Optional. Whether to resume the paused progress or not.

Callers 5

AutoplayFunction · 0.90
scrollFunction · 0.90
LiveFunction · 0.90
general.test.tsFile · 0.90
ThrottleFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…