@oscarpalmer/timer 0.34.0 → 0.35.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.
@@ -13,6 +13,7 @@ function calculate() {
13
13
  requestAnimationFrame(step);
14
14
  });
15
15
  }
16
+ const defaultTimeout = 3e4;
16
17
  const activeTimers = /* @__PURE__ */ new Set();
17
18
  const intervalBuffer = 5;
18
19
  const destroyedMessage = "Timer has already been destroyed";
@@ -39,6 +40,7 @@ exports.WORK_RESTART = WORK_RESTART;
39
40
  exports.WORK_START = WORK_START;
40
41
  exports.WORK_STOP = WORK_STOP;
41
42
  exports.activeTimers = activeTimers;
43
+ exports.defaultTimeout = defaultTimeout;
42
44
  exports.destroyedMessage = destroyedMessage;
43
45
  exports.hiddenTimers = hiddenTimers;
44
46
  exports.intervalBuffer = intervalBuffer;
package/dist/constants.js CHANGED
@@ -13,6 +13,7 @@ function calculate() {
13
13
  requestAnimationFrame(step);
14
14
  });
15
15
  }
16
+ const defaultTimeout = 3e4;
16
17
  const activeTimers = /* @__PURE__ */ new Set();
17
18
  const intervalBuffer = 5;
18
19
  const destroyedMessage = "Timer has already been destroyed";
@@ -30,4 +31,4 @@ let milliseconds = 1e3 / 60;
30
31
  calculate().then((value) => {
31
32
  milliseconds = value;
32
33
  });
33
- export { TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP, activeTimers, destroyedMessage, hiddenTimers, intervalBuffer, milliseconds, startedMessage };
34
+ export { TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP, activeTimers, defaultTimeout, destroyedMessage, hiddenTimers, intervalBuffer, milliseconds, startedMessage };
package/dist/get.cjs CHANGED
@@ -4,7 +4,7 @@ function getCallback(value) {
4
4
  return typeof value === "function" ? value : __oscarpalmer_atoms_function.noop;
5
5
  }
6
6
  function getValidNumber(value, defaultValue) {
7
- return typeof value === "number" && value > (defaultValue ?? 0) ? value : defaultValue ?? 0;
7
+ return typeof value === "number" ? value > 0 ? value : 0 : defaultValue ?? 0;
8
8
  }
9
9
  exports.getCallback = getCallback;
10
10
  exports.getValidNumber = getValidNumber;
package/dist/get.js CHANGED
@@ -3,6 +3,6 @@ function getCallback(value) {
3
3
  return typeof value === "function" ? value : noop;
4
4
  }
5
5
  function getValidNumber(value, defaultValue) {
6
- return typeof value === "number" && value > (defaultValue ?? 0) ? value : defaultValue ?? 0;
6
+ return typeof value === "number" ? value > 0 ? value : 0 : defaultValue ?? 0;
7
7
  }
8
8
  export { getCallback, getValidNumber };
package/dist/timer.cjs CHANGED
@@ -3,6 +3,7 @@ const require_constants = require("./constants.cjs");
3
3
  const require_work = require("./work.cjs");
4
4
  const __oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(require("@oscarpalmer/atoms/function"));
5
5
  var Timer = class {
6
+ state;
6
7
  get active() {
7
8
  return this.state.active;
8
9
  }
@@ -22,6 +22,8 @@ function calculate$1() {
22
22
  requestAnimationFrame(step);
23
23
  });
24
24
  }
25
+ //
26
+ const defaultTimeout = 30_000;
25
27
  /**
26
28
  * A set of all active timers
27
29
  */
@@ -99,9 +101,11 @@ function getCallback(value) {
99
101
  return typeof value === 'function' ? value : noop;
100
102
  }
101
103
  function getValidNumber(value, defaultValue) {
102
- return typeof value === 'number' && value > (defaultValue ?? 0)
103
- ? value
104
- : defaultValue ?? 0;
104
+ return typeof value === 'number'
105
+ ? value > 0
106
+ ? value
107
+ : 0
108
+ : (defaultValue ?? 0);
105
109
  }
106
110
 
107
111
  /**
@@ -462,7 +466,7 @@ class When {
462
466
  },
463
467
  count: getValidNumber(options?.count),
464
468
  interval: getValidNumber(options?.interval, milliseconds),
465
- timeout: getValidNumber(options?.timeout),
469
+ timeout: getValidNumber(options?.timeout, defaultTimeout),
466
470
  }, false);
467
471
  }
468
472
  /**
package/dist/timer.js CHANGED
@@ -2,6 +2,7 @@ import { WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP } from "
2
2
  import { stop, work } from "./work.js";
3
3
  import { noop } from "@oscarpalmer/atoms/function";
4
4
  var Timer = class {
5
+ state;
5
6
  get active() {
6
7
  return this.state.active;
7
8
  }
package/dist/when.cjs CHANGED
@@ -57,7 +57,7 @@ var When = class {
57
57
  },
58
58
  count: require_get.getValidNumber(options?.count),
59
59
  interval: require_get.getValidNumber(options?.interval, require_constants.milliseconds),
60
- timeout: require_get.getValidNumber(options?.timeout)
60
+ timeout: require_get.getValidNumber(options?.timeout, require_constants.defaultTimeout)
61
61
  }, false);
62
62
  }
63
63
  continue() {
package/dist/when.js CHANGED
@@ -1,4 +1,4 @@
1
- import { TYPE_WHEN, destroyedMessage, milliseconds, startedMessage } from "./constants.js";
1
+ import { TYPE_WHEN, defaultTimeout, destroyedMessage, milliseconds, startedMessage } from "./constants.js";
2
2
  import { getValidNumber } from "./get.js";
3
3
  import "./global.js";
4
4
  import { TimerTrace } from "./models.js";
@@ -56,7 +56,7 @@ var When = class {
56
56
  },
57
57
  count: getValidNumber(options?.count),
58
58
  interval: getValidNumber(options?.interval, milliseconds),
59
- timeout: getValidNumber(options?.timeout)
59
+ timeout: getValidNumber(options?.timeout, defaultTimeout)
60
60
  }, false);
61
61
  }
62
62
  continue() {
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "dts-bundle-generator": "^9.5",
17
17
  "glob": "^11",
18
18
  "jsdom": "^26.1",
19
- "rollup": "^4.47",
19
+ "rollup": "^4.49",
20
20
  "tslib": "^2.8",
21
21
  "typescript": "^5.9",
22
22
  "vite": "npm:rolldown-vite@latest",
@@ -95,5 +95,5 @@
95
95
  },
96
96
  "type": "module",
97
97
  "types": "types/index.d.cts",
98
- "version": "0.34.0"
98
+ "version": "0.35.0"
99
99
  }
package/src/constants.ts CHANGED
@@ -32,6 +32,10 @@ function calculate(): Promise<number> {
32
32
  });
33
33
  }
34
34
 
35
+ //
36
+
37
+ export const defaultTimeout = 30_000;
38
+
35
39
  /**
36
40
  * A set of all active timers
37
41
  */
package/src/get.ts CHANGED
@@ -6,7 +6,9 @@ export function getCallback(value: unknown): GenericCallback {
6
6
  }
7
7
 
8
8
  export function getValidNumber(value: unknown, defaultValue?: number): number {
9
- return typeof value === 'number' && value > (defaultValue ?? 0)
10
- ? value
11
- : defaultValue ?? 0;
9
+ return typeof value === 'number'
10
+ ? value > 0
11
+ ? value
12
+ : 0
13
+ : (defaultValue ?? 0);
12
14
  }
package/src/when.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {noop} from '@oscarpalmer/atoms/function';
2
2
  import {
3
+ defaultTimeout,
3
4
  destroyedMessage,
4
5
  milliseconds,
5
6
  startedMessage,
@@ -12,6 +13,7 @@ import {Timer} from './timer';
12
13
 
13
14
  class When {
14
15
  private readonly $timer = TYPE_WHEN;
16
+
15
17
  private readonly state: WhenState = {
16
18
  promise: undefined as never,
17
19
  rejecter: undefined as never,
@@ -93,7 +95,7 @@ class When {
93
95
  },
94
96
  count: getValidNumber(options?.count),
95
97
  interval: getValidNumber(options?.interval, milliseconds),
96
- timeout: getValidNumber(options?.timeout),
98
+ timeout: getValidNumber(options?.timeout, defaultTimeout),
97
99
  },
98
100
  false,
99
101
  );
@@ -67,6 +67,7 @@ export type TimerState = {
67
67
  };
68
68
  export type TimerType = "repeat" | "wait" | "when";
69
69
  export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
70
+ export declare const defaultTimeout = 30000;
70
71
  /**
71
72
  * A set of all active timers
72
73
  */
@@ -1,5 +1,6 @@
1
1
  import type { TimerType, WorkHandlerType } from './models';
2
2
  import type { Timer } from './timer';
3
+ export declare const defaultTimeout = 30000;
3
4
  /**
4
5
  * A set of all active timers
5
6
  */