@oscarpalmer/timer 0.44.0 → 0.45.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.
- package/dist/constants.d.mts +3 -14
- package/dist/constants.mjs +5 -13
- package/dist/global.d.mts +3 -0
- package/dist/global.mjs +5 -14
- package/dist/index.d.mts +12 -33
- package/dist/index.mjs +132 -252
- package/dist/misc.d.mts +10 -0
- package/dist/misc.mjs +34 -0
- package/dist/models.d.mts +24 -3
- package/dist/repeat.mjs +1 -1
- package/dist/timer.mjs +14 -27
- package/dist/wait.mjs +1 -1
- package/dist/when.mjs +11 -24
- package/dist/work.d.mts +3 -3
- package/dist/work.mjs +26 -31
- package/package.json +2 -6
- package/src/constants.ts +5 -15
- package/src/global.ts +11 -21
- package/src/index.ts +0 -1
- package/src/misc.ts +49 -0
- package/src/models.ts +24 -2
- package/src/repeat.ts +1 -1
- package/src/timer.ts +16 -42
- package/src/wait.ts +1 -1
- package/src/when.ts +12 -33
- package/src/work.ts +33 -56
- package/dist/delay.d.mts +0 -2
- package/dist/delay.mjs +0 -2
- package/dist/get.d.mts +0 -7
- package/dist/get.mjs +0 -15
- package/src/delay.ts +0 -1
- package/src/get.ts +0 -17
package/dist/constants.d.mts
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TimerName, TimerStates, WorkHandlerType } from "./models.mjs";
|
|
2
2
|
//#region src/constants.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Buffer value to use when evaluating if a specific time is within a certain range
|
|
5
5
|
*/
|
|
6
6
|
declare const BUFFER_INTERVAL = 5;
|
|
7
7
|
declare const DEFAULT_TIMEOUT = 30000;
|
|
8
|
-
/**
|
|
9
|
-
* Message to show when a when-timer is destroyed
|
|
10
|
-
*/
|
|
11
|
-
declare const MESSAGE_DESTROYED = "Timer has already been destroyed";
|
|
12
8
|
/**
|
|
13
9
|
* Message to show when a when-timer is started
|
|
14
10
|
*/
|
|
15
11
|
declare const MESSAGE_STARTED = "Timer has already been started";
|
|
16
|
-
|
|
17
|
-
* A set of all active timers
|
|
18
|
-
*/
|
|
19
|
-
declare const TIMERS_ACTIVE: Set<Timer>;
|
|
20
|
-
/**
|
|
21
|
-
* A set of timers that were paused due to the document being hidden
|
|
22
|
-
*/
|
|
23
|
-
declare const TIMERS_HIDDEN: Set<Timer>;
|
|
12
|
+
declare const STATES: TimerStates;
|
|
24
13
|
declare const TYPE_REPEAT: TimerName;
|
|
25
14
|
declare const TYPE_WAIT: TimerName;
|
|
26
15
|
declare const TYPE_WHEN: TimerName;
|
|
@@ -30,4 +19,4 @@ declare const WORK_RESTART: WorkHandlerType;
|
|
|
30
19
|
declare const WORK_START: WorkHandlerType;
|
|
31
20
|
declare const WORK_STOP: WorkHandlerType;
|
|
32
21
|
//#endregion
|
|
33
|
-
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT,
|
|
22
|
+
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT, MESSAGE_STARTED, STATES, TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP };
|
package/dist/constants.mjs
CHANGED
|
@@ -5,21 +5,13 @@
|
|
|
5
5
|
const BUFFER_INTERVAL = 5;
|
|
6
6
|
const DEFAULT_TIMEOUT = 3e4;
|
|
7
7
|
/**
|
|
8
|
-
* Message to show when a when-timer is destroyed
|
|
9
|
-
*/
|
|
10
|
-
const MESSAGE_DESTROYED = "Timer has already been destroyed";
|
|
11
|
-
/**
|
|
12
8
|
* Message to show when a when-timer is started
|
|
13
9
|
*/
|
|
14
10
|
const MESSAGE_STARTED = "Timer has already been started";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A set of timers that were paused due to the document being hidden
|
|
21
|
-
*/
|
|
22
|
-
const TIMERS_HIDDEN = /* @__PURE__ */ new Set();
|
|
11
|
+
const STATES = {
|
|
12
|
+
active: /* @__PURE__ */ new Set(),
|
|
13
|
+
hidden: /* @__PURE__ */ new Set()
|
|
14
|
+
};
|
|
23
15
|
const TYPE_REPEAT = "repeat";
|
|
24
16
|
const TYPE_WAIT = "wait";
|
|
25
17
|
const TYPE_WHEN = "when";
|
|
@@ -29,4 +21,4 @@ const WORK_RESTART = "restart";
|
|
|
29
21
|
const WORK_START = "start";
|
|
30
22
|
const WORK_STOP = "stop";
|
|
31
23
|
//#endregion
|
|
32
|
-
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT,
|
|
24
|
+
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT, MESSAGE_STARTED, STATES, TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP };
|
package/dist/global.d.mts
CHANGED
|
@@ -2,5 +2,8 @@ import { Timer } from "./models.mjs";
|
|
|
2
2
|
//#region src/global.d.ts
|
|
3
3
|
declare global {
|
|
4
4
|
var _oscarpalmer_timer_debug: boolean | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* All active timers _(or `undefined` if debugging is not enabled)_
|
|
7
|
+
*/
|
|
5
8
|
var _oscarpalmer_timers: Timer[] | undefined;
|
|
6
9
|
}
|
package/dist/global.mjs
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { STATES } from "./constants.mjs";
|
|
2
|
+
import { onVisibilityChange } from "./misc.mjs";
|
|
2
3
|
//#region src/global.ts
|
|
3
|
-
|
|
4
|
-
return globalThis._oscarpalmer_timer_debug ? [...
|
|
4
|
+
Object.defineProperty(globalThis, "_oscarpalmer_timers", { get() {
|
|
5
|
+
return globalThis._oscarpalmer_timer_debug ? [...STATES.active].map((state) => state.timer) : [];
|
|
5
6
|
} });
|
|
6
|
-
|
|
7
|
-
document.addEventListener("visibilitychange", () => {
|
|
8
|
-
const from = document.hidden ? TIMERS_ACTIVE : TIMERS_HIDDEN;
|
|
9
|
-
const method = document.hidden ? WORK_PAUSE : WORK_CONTINUE;
|
|
10
|
-
const to = document.hidden ? TIMERS_HIDDEN : TIMERS_ACTIVE;
|
|
11
|
-
for (const timer of from) {
|
|
12
|
-
timer[method]();
|
|
13
|
-
to.add(timer);
|
|
14
|
-
}
|
|
15
|
-
from.clear();
|
|
16
|
-
});
|
|
7
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
17
8
|
//#endregion
|
|
18
9
|
export {};
|
package/dist/index.d.mts
CHANGED
|
@@ -31,6 +31,8 @@ type Timer = {
|
|
|
31
31
|
get active(): boolean;
|
|
32
32
|
/**
|
|
33
33
|
* Is the timer destroyed?
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Timers take care of their own cleanup; this always returns `false`
|
|
34
36
|
*/
|
|
35
37
|
get destroyed(): boolean;
|
|
36
38
|
/**
|
|
@@ -47,6 +49,8 @@ type Timer = {
|
|
|
47
49
|
continue(): Timer;
|
|
48
50
|
/**
|
|
49
51
|
* Destroy the timer
|
|
52
|
+
*
|
|
53
|
+
* @deprecated Timers take care of their own cleanup
|
|
50
54
|
*/
|
|
51
55
|
destroy(): void;
|
|
52
56
|
/**
|
|
@@ -80,6 +84,8 @@ type When = {
|
|
|
80
84
|
get active(): boolean;
|
|
81
85
|
/**
|
|
82
86
|
* Is the timer destroyed?
|
|
87
|
+
*
|
|
88
|
+
* @deprecated Timers take care of their own cleanup; this always returns `false`
|
|
83
89
|
*/
|
|
84
90
|
get destroyed(): boolean;
|
|
85
91
|
/**
|
|
@@ -96,6 +102,8 @@ type When = {
|
|
|
96
102
|
continue(): When;
|
|
97
103
|
/**
|
|
98
104
|
* Destroys the timer _(and stops it,if it was running)_
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Timers take care of their own cleanup
|
|
99
107
|
*/
|
|
100
108
|
destroy(): void;
|
|
101
109
|
/**
|
|
@@ -135,40 +143,11 @@ type WhenOptions = {
|
|
|
135
143
|
//#region src/global.d.ts
|
|
136
144
|
declare global {
|
|
137
145
|
var _oscarpalmer_timer_debug: boolean | undefined;
|
|
138
|
-
var _oscarpalmer_timers: Timer[] | undefined;
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region node_modules/@oscarpalmer/atoms/dist/promise/models.d.mts
|
|
142
|
-
/**
|
|
143
|
-
* Options for a _Promise_-handling function
|
|
144
|
-
*/
|
|
145
|
-
type PromiseOptions = {
|
|
146
|
-
/**
|
|
147
|
-
* AbortSignal for aborting the _Promise_; when aborted, the _Promise_ will reject with the reason of the signal
|
|
148
|
-
*/
|
|
149
|
-
signal?: AbortSignal;
|
|
150
146
|
/**
|
|
151
|
-
*
|
|
147
|
+
* All active timers _(or `undefined` if debugging is not enabled)_
|
|
152
148
|
*/
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region node_modules/@oscarpalmer/atoms/dist/promise/delay.d.mts
|
|
157
|
-
//#region src/promise/delay.d.ts
|
|
158
|
-
/**
|
|
159
|
-
* Create a delayed promise that resolves after a certain amount of time, or rejects if aborted
|
|
160
|
-
*
|
|
161
|
-
* @param options Options for the delay
|
|
162
|
-
* @returns Delayed promise
|
|
163
|
-
*/
|
|
164
|
-
declare function delay(options?: PromiseOptions): Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* Create a delayed promise that resolves after a certain amount of time
|
|
167
|
-
*
|
|
168
|
-
* @param time How long to wait for _(in milliseconds; defaults to `0`)_
|
|
169
|
-
* @returns Delayed promise
|
|
170
|
-
*/
|
|
171
|
-
declare function delay(time?: number): Promise<void>;
|
|
149
|
+
var _oscarpalmer_timers: Timer[] | undefined;
|
|
150
|
+
}
|
|
172
151
|
//#endregion
|
|
173
152
|
//#region src/is.d.ts
|
|
174
153
|
/**
|
|
@@ -224,4 +203,4 @@ declare function wait(callback: () => void, time?: number): Timer;
|
|
|
224
203
|
*/
|
|
225
204
|
declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
226
205
|
//#endregion
|
|
227
|
-
export { type RepeatOptions, type Timer, type TimerOptions, type When, type WhenOptions,
|
|
206
|
+
export { type RepeatOptions, type Timer, type TimerOptions, type When, type WhenOptions, isRepeated, isTimer, isWaited, isWhen, repeat, wait, when };
|