@provex/react 1.11.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview Clock seam for time-dependent logic.
3
+ *
4
+ * Code that reads the current time or schedules timers takes a `Clock`
5
+ * instead of calling the globals. Production code uses `systemClock`.
6
+ * Tests pass the deterministic clock from `@provex/react/testing`.
7
+ */
8
+ /** Opaque handle returned by `Clock.setTimeout` and `Clock.setInterval`. */
9
+ type TimerHandle = ReturnType<typeof setTimeout>;
10
+ /** The time and timer functions that time-dependent code needs. */
11
+ interface Clock {
12
+ /** Current time in milliseconds since the Unix epoch. */
13
+ now(): number;
14
+ /** Run `callback` once after `delayMs` milliseconds. */
15
+ setTimeout(callback: () => void, delayMs: number): TimerHandle;
16
+ /** Cancel a timer created by `setTimeout`. */
17
+ clearTimeout(handle: TimerHandle): void;
18
+ /** Run `callback` every `intervalMs` milliseconds. */
19
+ setInterval(callback: () => void, intervalMs: number): TimerHandle;
20
+ /** Cancel a timer created by `setInterval`. */
21
+ clearInterval(handle: TimerHandle): void;
22
+ }
23
+ /**
24
+ * The real clock. Each call reads the global at call time, so code that
25
+ * replaces the globals (for example `vi.useFakeTimers`) still takes effect.
26
+ */
27
+ declare const systemClock: Clock;
28
+
29
+ export { type Clock as C, type TimerHandle as T, systemClock as s };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview Clock seam for time-dependent logic.
3
+ *
4
+ * Code that reads the current time or schedules timers takes a `Clock`
5
+ * instead of calling the globals. Production code uses `systemClock`.
6
+ * Tests pass the deterministic clock from `@provex/react/testing`.
7
+ */
8
+ /** Opaque handle returned by `Clock.setTimeout` and `Clock.setInterval`. */
9
+ type TimerHandle = ReturnType<typeof setTimeout>;
10
+ /** The time and timer functions that time-dependent code needs. */
11
+ interface Clock {
12
+ /** Current time in milliseconds since the Unix epoch. */
13
+ now(): number;
14
+ /** Run `callback` once after `delayMs` milliseconds. */
15
+ setTimeout(callback: () => void, delayMs: number): TimerHandle;
16
+ /** Cancel a timer created by `setTimeout`. */
17
+ clearTimeout(handle: TimerHandle): void;
18
+ /** Run `callback` every `intervalMs` milliseconds. */
19
+ setInterval(callback: () => void, intervalMs: number): TimerHandle;
20
+ /** Cancel a timer created by `setInterval`. */
21
+ clearInterval(handle: TimerHandle): void;
22
+ }
23
+ /**
24
+ * The real clock. Each call reads the global at call time, so code that
25
+ * replaces the globals (for example `vi.useFakeTimers`) still takes effect.
26
+ */
27
+ declare const systemClock: Clock;
28
+
29
+ export { type Clock as C, type TimerHandle as T, systemClock as s };