Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93cf58a

Browse files
committed
fix: make error case more clear
1 parent 5233fb8 commit 93cf58a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

site/src/hooks/useTimeSync.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* @todo Things that still need to be done before this can be called done:
3-
*
4-
* 1. Fill out all incomplete methods
5-
* 2. Add tests
3+
* 1. Add tests and address any bugs
64
*/
75
import {
86
type FC,
@@ -233,7 +231,7 @@ function areDepsInvalidated(
233231
return false;
234232
}
235233

236-
type UseTimeSyncSelectOptions<T = Date> = Readonly<
234+
type UseTimeSyncSelectOptions<T> = Readonly<
237235
UseTimeSyncOptions & {
238236
/**
239237
* selectDependencies acts like the dependency array for a useMemo
@@ -271,9 +269,7 @@ type UseTimeSyncSelectOptions<T = Date> = Readonly<
271269
* frequent update interval, both component instances will update on that
272270
* interval.
273271
*/
274-
export function useTimeSyncSelect<T = Date>(
275-
options: UseTimeSyncSelectOptions<T>,
276-
): T {
272+
export function useTimeSyncSelect<T>(options: UseTimeSyncSelectOptions<T>): T {
277273
const { select, selectDependencies, targetRefreshInterval } = options;
278274
const hookId = useId();
279275
const timeSync = useTimeSyncContext();

site/src/utils/TimeSync.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* @todo What's left to do here:
33
* 1. Fill out all incomplete methods
4-
* 2. Make sure the class respects the resyncOnNewSubscription option
5-
* 3. Add tests
4+
* 2. Refactor as necessary
5+
* 3. Add tests and address any bugs
66
*/
77
export const TARGET_REFRESH_ONE_SECOND = 1_000;
88
export const TARGET_REFRESH_ONE_MINUTE = 60 * 1_000;
@@ -213,9 +213,13 @@ export class TimeSync implements TimeSyncApi {
213213
}
214214

215215
subscribe(entry: SubscriptionEntry): void {
216-
if (entry.targetRefreshInterval <= 0) {
216+
const intervalIsValid =
217+
entry.targetRefreshInterval > 0 &&
218+
(Number.isInteger(entry.targetRefreshInterval) ||
219+
entry.targetRefreshInterval === Number.POSITIVE_INFINITY);
220+
if (!intervalIsValid) {
217221
throw new Error(
218-
`Refresh interval ${entry.targetRefreshInterval} must be a positive integer (or Infinity)`,
222+
`Refresh interval ${entry.targetRefreshInterval} must be a positive integer or Positive Infinity)`,
219223
);
220224
}
221225

0 commit comments

Comments
 (0)