@oscarpalmer/timer 0.49.0 → 0.50.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/index.mjs +31 -40
- package/dist/timer.mjs +18 -21
- package/dist/when.mjs +13 -19
- package/package.json +4 -4
- package/src/timer.ts +29 -45
- package/src/when.ts +15 -30
package/dist/index.mjs
CHANGED
|
@@ -194,7 +194,7 @@ var TimerTrace = class extends Error {
|
|
|
194
194
|
//#endregion
|
|
195
195
|
//#region src/timer.ts
|
|
196
196
|
function Timer(name, state, options, start) {
|
|
197
|
-
|
|
197
|
+
this[SYMBOL] = {
|
|
198
198
|
...state,
|
|
199
199
|
name,
|
|
200
200
|
options,
|
|
@@ -206,30 +206,27 @@ function Timer(name, state, options, start) {
|
|
|
206
206
|
paused: false,
|
|
207
207
|
timer: void 0,
|
|
208
208
|
total: 0
|
|
209
|
-
}
|
|
209
|
+
};
|
|
210
210
|
if (start) startTimer.call(this);
|
|
211
211
|
}
|
|
212
|
+
Timer.prototype.continue = continueTimer;
|
|
213
|
+
Timer.prototype.pause = pauseTimer;
|
|
214
|
+
Timer.prototype.restart = restartTimer;
|
|
215
|
+
Timer.prototype.start = startTimer;
|
|
216
|
+
Timer.prototype.stop = stopTimer;
|
|
212
217
|
Object.defineProperties(Timer.prototype, {
|
|
213
218
|
active: {
|
|
214
219
|
enumerable: true,
|
|
215
|
-
get
|
|
216
|
-
return isActiveTimer.call(this);
|
|
217
|
-
}
|
|
220
|
+
get: getTimerActive
|
|
218
221
|
},
|
|
219
|
-
continue: { value: continueTimer },
|
|
220
|
-
pause: { value: pauseTimer },
|
|
221
222
|
paused: {
|
|
222
223
|
enumerable: true,
|
|
223
|
-
get
|
|
224
|
-
return isPausedTimer.call(this);
|
|
225
|
-
}
|
|
224
|
+
get: getTimerPaused
|
|
226
225
|
},
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return getTimerTrace.call(this);
|
|
232
|
-
} }
|
|
226
|
+
trace: {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
get: getTimerTrace
|
|
229
|
+
}
|
|
233
230
|
});
|
|
234
231
|
function continueTimer() {
|
|
235
232
|
return work(WORK_CONTINUE, this[SYMBOL]);
|
|
@@ -237,15 +234,15 @@ function continueTimer() {
|
|
|
237
234
|
function createTimer(name, state, options, start) {
|
|
238
235
|
return new Timer(name, state, options, start);
|
|
239
236
|
}
|
|
240
|
-
function
|
|
241
|
-
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].trace : void 0;
|
|
242
|
-
}
|
|
243
|
-
function isActiveTimer() {
|
|
237
|
+
function getTimerActive() {
|
|
244
238
|
return this[SYMBOL].active && !this[SYMBOL].paused;
|
|
245
239
|
}
|
|
246
|
-
function
|
|
240
|
+
function getTimerPaused() {
|
|
247
241
|
return this[SYMBOL].paused;
|
|
248
242
|
}
|
|
243
|
+
function getTimerTrace() {
|
|
244
|
+
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].trace : void 0;
|
|
245
|
+
}
|
|
249
246
|
function pauseTimer() {
|
|
250
247
|
return work(WORK_PAUSE, this[SYMBOL]);
|
|
251
248
|
}
|
|
@@ -310,7 +307,7 @@ function When(condition, options) {
|
|
|
310
307
|
started: false,
|
|
311
308
|
timer: void 0
|
|
312
309
|
};
|
|
313
|
-
|
|
310
|
+
this[SYMBOL] = state;
|
|
314
311
|
state.promise = new Promise((resolve, reject) => {
|
|
315
312
|
state.resolver = resolve;
|
|
316
313
|
state.rejecter = reject;
|
|
@@ -324,20 +321,14 @@ function When(condition, options) {
|
|
|
324
321
|
onError: () => state.rejecter?.()
|
|
325
322
|
}, false);
|
|
326
323
|
}
|
|
324
|
+
When.prototype.continue = continueWhen;
|
|
325
|
+
When.prototype.pause = pauseWhen;
|
|
326
|
+
When.prototype.start = startWhen;
|
|
327
|
+
When.prototype.stop = stopWhen;
|
|
327
328
|
Object.defineProperties(When.prototype, {
|
|
328
|
-
active: { get
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
continue: { value: continueWhen },
|
|
332
|
-
pause: { value: pauseWhen },
|
|
333
|
-
paused: { get() {
|
|
334
|
-
return isPausedWhen.call(this);
|
|
335
|
-
} },
|
|
336
|
-
start: { value: startWhen },
|
|
337
|
-
stop: { value: stopWhen },
|
|
338
|
-
trace: { get() {
|
|
339
|
-
return getWhenTrace.call(this);
|
|
340
|
-
} }
|
|
329
|
+
active: { get: getWhenActive },
|
|
330
|
+
paused: { get: getWhenPaused },
|
|
331
|
+
trace: { get: getWhenTrace }
|
|
341
332
|
});
|
|
342
333
|
function continueWhen() {
|
|
343
334
|
return onWhen(WORK_CONTINUE, this, this[SYMBOL]);
|
|
@@ -350,15 +341,15 @@ function getWhenOptions(input) {
|
|
|
350
341
|
timeout: getValidTimeout(options?.timeout)
|
|
351
342
|
};
|
|
352
343
|
}
|
|
353
|
-
function
|
|
354
|
-
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].timer?.trace : void 0;
|
|
355
|
-
}
|
|
356
|
-
function isActiveWhen() {
|
|
344
|
+
function getWhenActive() {
|
|
357
345
|
return this[SYMBOL].timer.active;
|
|
358
346
|
}
|
|
359
|
-
function
|
|
347
|
+
function getWhenPaused() {
|
|
360
348
|
return this[SYMBOL].timer.paused;
|
|
361
349
|
}
|
|
350
|
+
function getWhenTrace() {
|
|
351
|
+
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].timer?.trace : void 0;
|
|
352
|
+
}
|
|
362
353
|
function onAfter(state) {
|
|
363
354
|
if (state.result) state.resolver?.();
|
|
364
355
|
else state.rejecter?.();
|
package/dist/timer.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { SYMBOL, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP
|
|
|
2
2
|
import { work } from "./work.mjs";
|
|
3
3
|
//#region src/timer.ts
|
|
4
4
|
function Timer(name, state, options, start) {
|
|
5
|
-
|
|
5
|
+
this[SYMBOL] = {
|
|
6
6
|
...state,
|
|
7
7
|
name,
|
|
8
8
|
options,
|
|
@@ -14,30 +14,27 @@ function Timer(name, state, options, start) {
|
|
|
14
14
|
paused: false,
|
|
15
15
|
timer: void 0,
|
|
16
16
|
total: 0
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
if (start) startTimer.call(this);
|
|
19
19
|
}
|
|
20
|
+
Timer.prototype.continue = continueTimer;
|
|
21
|
+
Timer.prototype.pause = pauseTimer;
|
|
22
|
+
Timer.prototype.restart = restartTimer;
|
|
23
|
+
Timer.prototype.start = startTimer;
|
|
24
|
+
Timer.prototype.stop = stopTimer;
|
|
20
25
|
Object.defineProperties(Timer.prototype, {
|
|
21
26
|
active: {
|
|
22
27
|
enumerable: true,
|
|
23
|
-
get
|
|
24
|
-
return isActiveTimer.call(this);
|
|
25
|
-
}
|
|
28
|
+
get: getTimerActive
|
|
26
29
|
},
|
|
27
|
-
continue: { value: continueTimer },
|
|
28
|
-
pause: { value: pauseTimer },
|
|
29
30
|
paused: {
|
|
30
31
|
enumerable: true,
|
|
31
|
-
get
|
|
32
|
-
return isPausedTimer.call(this);
|
|
33
|
-
}
|
|
32
|
+
get: getTimerPaused
|
|
34
33
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return getTimerTrace.call(this);
|
|
40
|
-
} }
|
|
34
|
+
trace: {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: getTimerTrace
|
|
37
|
+
}
|
|
41
38
|
});
|
|
42
39
|
function continueTimer() {
|
|
43
40
|
return work(WORK_CONTINUE, this[SYMBOL]);
|
|
@@ -45,15 +42,15 @@ function continueTimer() {
|
|
|
45
42
|
function createTimer(name, state, options, start) {
|
|
46
43
|
return new Timer(name, state, options, start);
|
|
47
44
|
}
|
|
48
|
-
function
|
|
49
|
-
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].trace : void 0;
|
|
50
|
-
}
|
|
51
|
-
function isActiveTimer() {
|
|
45
|
+
function getTimerActive() {
|
|
52
46
|
return this[SYMBOL].active && !this[SYMBOL].paused;
|
|
53
47
|
}
|
|
54
|
-
function
|
|
48
|
+
function getTimerPaused() {
|
|
55
49
|
return this[SYMBOL].paused;
|
|
56
50
|
}
|
|
51
|
+
function getTimerTrace() {
|
|
52
|
+
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].trace : void 0;
|
|
53
|
+
}
|
|
57
54
|
function pauseTimer() {
|
|
58
55
|
return work(WORK_PAUSE, this[SYMBOL]);
|
|
59
56
|
}
|
package/dist/when.mjs
CHANGED
|
@@ -12,7 +12,7 @@ function When(condition, options) {
|
|
|
12
12
|
started: false,
|
|
13
13
|
timer: void 0
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
this[SYMBOL] = state;
|
|
16
16
|
state.promise = new Promise((resolve, reject) => {
|
|
17
17
|
state.resolver = resolve;
|
|
18
18
|
state.rejecter = reject;
|
|
@@ -26,20 +26,14 @@ function When(condition, options) {
|
|
|
26
26
|
onError: () => state.rejecter?.()
|
|
27
27
|
}, false);
|
|
28
28
|
}
|
|
29
|
+
When.prototype.continue = continueWhen;
|
|
30
|
+
When.prototype.pause = pauseWhen;
|
|
31
|
+
When.prototype.start = startWhen;
|
|
32
|
+
When.prototype.stop = stopWhen;
|
|
29
33
|
Object.defineProperties(When.prototype, {
|
|
30
|
-
active: { get
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
continue: { value: continueWhen },
|
|
34
|
-
pause: { value: pauseWhen },
|
|
35
|
-
paused: { get() {
|
|
36
|
-
return isPausedWhen.call(this);
|
|
37
|
-
} },
|
|
38
|
-
start: { value: startWhen },
|
|
39
|
-
stop: { value: stopWhen },
|
|
40
|
-
trace: { get() {
|
|
41
|
-
return getWhenTrace.call(this);
|
|
42
|
-
} }
|
|
34
|
+
active: { get: getWhenActive },
|
|
35
|
+
paused: { get: getWhenPaused },
|
|
36
|
+
trace: { get: getWhenTrace }
|
|
43
37
|
});
|
|
44
38
|
function continueWhen() {
|
|
45
39
|
return onWhen(WORK_CONTINUE, this, this[SYMBOL]);
|
|
@@ -52,15 +46,15 @@ function getWhenOptions(input) {
|
|
|
52
46
|
timeout: getValidTimeout(options?.timeout)
|
|
53
47
|
};
|
|
54
48
|
}
|
|
55
|
-
function
|
|
56
|
-
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].timer?.trace : void 0;
|
|
57
|
-
}
|
|
58
|
-
function isActiveWhen() {
|
|
49
|
+
function getWhenActive() {
|
|
59
50
|
return this[SYMBOL].timer.active;
|
|
60
51
|
}
|
|
61
|
-
function
|
|
52
|
+
function getWhenPaused() {
|
|
62
53
|
return this[SYMBOL].timer.paused;
|
|
63
54
|
}
|
|
55
|
+
function getWhenTrace() {
|
|
56
|
+
return globalThis._oscarpalmer_timer_debug ?? false ? this[SYMBOL].timer?.trace : void 0;
|
|
57
|
+
}
|
|
64
58
|
function onAfter(state) {
|
|
65
59
|
if (state.result) state.resolver?.();
|
|
66
60
|
else state.rejecter?.();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/timer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "A better solution for timeout- and interval-based timers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"requestAnimationFrame",
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"watch": "npx vite build --watch"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@oscarpalmer/atoms": "^0.
|
|
63
|
+
"@oscarpalmer/atoms": "^0.204"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@oxlint/plugins": "^1.
|
|
66
|
+
"@oxlint/plugins": "^1.83",
|
|
67
67
|
"@types/node": "^26.5",
|
|
68
68
|
"@vitest/coverage-istanbul": "^4.1",
|
|
69
|
-
"jsdom": "^30",
|
|
69
|
+
"jsdom": "^30.1",
|
|
70
70
|
"tsdown": "^0.23",
|
|
71
71
|
"typescript": "^6",
|
|
72
72
|
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
|
package/src/timer.ts
CHANGED
|
@@ -19,59 +19,43 @@ function Timer(
|
|
|
19
19
|
options: TimerOptions,
|
|
20
20
|
start: boolean,
|
|
21
21
|
) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
});
|
|
22
|
+
this[SYMBOL] = {
|
|
23
|
+
...state,
|
|
24
|
+
name,
|
|
25
|
+
options,
|
|
26
|
+
active: false,
|
|
27
|
+
destroyed: false,
|
|
28
|
+
elapsed: 0,
|
|
29
|
+
frame: undefined,
|
|
30
|
+
index: 0,
|
|
31
|
+
paused: false,
|
|
32
|
+
timer: undefined as never,
|
|
33
|
+
total: 0,
|
|
34
|
+
};
|
|
37
35
|
|
|
38
36
|
if (start) {
|
|
39
37
|
startTimer.call(this);
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
|
|
41
|
+
Timer.prototype.continue = continueTimer;
|
|
42
|
+
Timer.prototype.pause = pauseTimer;
|
|
43
|
+
Timer.prototype.restart = restartTimer;
|
|
44
|
+
Timer.prototype.start = startTimer;
|
|
45
|
+
Timer.prototype.stop = stopTimer;
|
|
46
|
+
|
|
43
47
|
Object.defineProperties(Timer.prototype, {
|
|
44
48
|
active: {
|
|
45
49
|
enumerable: true,
|
|
46
|
-
get
|
|
47
|
-
return isActiveTimer.call(this);
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
continue: {
|
|
51
|
-
value: continueTimer,
|
|
52
|
-
},
|
|
53
|
-
pause: {
|
|
54
|
-
value: pauseTimer,
|
|
50
|
+
get: getTimerActive,
|
|
55
51
|
},
|
|
56
52
|
paused: {
|
|
57
53
|
enumerable: true,
|
|
58
|
-
get
|
|
59
|
-
return isPausedTimer.call(this);
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
restart: {
|
|
63
|
-
value: restartTimer,
|
|
64
|
-
},
|
|
65
|
-
start: {
|
|
66
|
-
value: startTimer,
|
|
67
|
-
},
|
|
68
|
-
stop: {
|
|
69
|
-
value: stopTimer,
|
|
54
|
+
get: getTimerPaused,
|
|
70
55
|
},
|
|
71
56
|
trace: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: getTimerTrace,
|
|
75
59
|
},
|
|
76
60
|
});
|
|
77
61
|
|
|
@@ -93,18 +77,18 @@ export function createTimer(
|
|
|
93
77
|
return new Timer(name, state, options, start);
|
|
94
78
|
}
|
|
95
79
|
|
|
96
|
-
function
|
|
97
|
-
return (globalThis._oscarpalmer_timer_debug ?? false) ? this[SYMBOL].trace : undefined;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function isActiveTimer(this: InternalTimer): boolean {
|
|
80
|
+
function getTimerActive(this: InternalTimer): boolean {
|
|
101
81
|
return this[SYMBOL].active && !this[SYMBOL].paused;
|
|
102
82
|
}
|
|
103
83
|
|
|
104
|
-
function
|
|
84
|
+
function getTimerPaused(this: InternalTimer): boolean {
|
|
105
85
|
return this[SYMBOL].paused;
|
|
106
86
|
}
|
|
107
87
|
|
|
88
|
+
function getTimerTrace(this: InternalTimer): string | undefined {
|
|
89
|
+
return (globalThis._oscarpalmer_timer_debug ?? false) ? this[SYMBOL].trace : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
108
92
|
function pauseTimer(this: InternalTimer): Timer {
|
|
109
93
|
return work(WORK_PAUSE, this[SYMBOL]);
|
|
110
94
|
}
|
package/src/when.ts
CHANGED
|
@@ -36,9 +36,7 @@ function When(this: any, condition: () => boolean, options: WhenOptions) {
|
|
|
36
36
|
timer: undefined as never,
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
value: state,
|
|
41
|
-
});
|
|
39
|
+
this[SYMBOL] = state;
|
|
42
40
|
|
|
43
41
|
state.promise = new Promise<void>((resolve, reject) => {
|
|
44
42
|
state.resolver = resolve;
|
|
@@ -60,33 +58,20 @@ function When(this: any, condition: () => boolean, options: WhenOptions) {
|
|
|
60
58
|
);
|
|
61
59
|
}
|
|
62
60
|
|
|
61
|
+
When.prototype.continue = continueWhen;
|
|
62
|
+
When.prototype.pause = pauseWhen;
|
|
63
|
+
When.prototype.start = startWhen;
|
|
64
|
+
When.prototype.stop = stopWhen;
|
|
65
|
+
|
|
63
66
|
Object.defineProperties(When.prototype, {
|
|
64
67
|
active: {
|
|
65
|
-
get
|
|
66
|
-
return isActiveWhen.call(this);
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
continue: {
|
|
70
|
-
value: continueWhen,
|
|
71
|
-
},
|
|
72
|
-
pause: {
|
|
73
|
-
value: pauseWhen,
|
|
68
|
+
get: getWhenActive,
|
|
74
69
|
},
|
|
75
70
|
paused: {
|
|
76
|
-
get
|
|
77
|
-
return isPausedWhen.call(this);
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
start: {
|
|
81
|
-
value: startWhen,
|
|
82
|
-
},
|
|
83
|
-
stop: {
|
|
84
|
-
value: stopWhen,
|
|
71
|
+
get: getWhenPaused,
|
|
85
72
|
},
|
|
86
73
|
trace: {
|
|
87
|
-
get
|
|
88
|
-
return getWhenTrace.call(this);
|
|
89
|
-
},
|
|
74
|
+
get: getWhenTrace,
|
|
90
75
|
},
|
|
91
76
|
});
|
|
92
77
|
|
|
@@ -109,18 +94,18 @@ function getWhenOptions(input: unknown): WhenOptions {
|
|
|
109
94
|
};
|
|
110
95
|
}
|
|
111
96
|
|
|
112
|
-
function
|
|
113
|
-
return (globalThis._oscarpalmer_timer_debug ?? false) ? this[SYMBOL].timer?.trace : undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function isActiveWhen(this: InternalWhen): boolean {
|
|
97
|
+
function getWhenActive(this: InternalWhen): boolean {
|
|
117
98
|
return this[SYMBOL].timer.active;
|
|
118
99
|
}
|
|
119
100
|
|
|
120
|
-
function
|
|
101
|
+
function getWhenPaused(this: InternalWhen): boolean {
|
|
121
102
|
return this[SYMBOL].timer.paused;
|
|
122
103
|
}
|
|
123
104
|
|
|
105
|
+
function getWhenTrace(this: InternalWhen): string | undefined {
|
|
106
|
+
return (globalThis._oscarpalmer_timer_debug ?? false) ? this[SYMBOL].timer?.trace : undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
124
109
|
function onAfter(state: WhenState): void {
|
|
125
110
|
if (state.result) {
|
|
126
111
|
state.resolver?.();
|