@oscarpalmer/timer 0.24.0 → 0.25.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/functions.mjs +5 -5
- package/dist/global.mjs +1 -1
- package/dist/index.js +5 -5
- package/dist/index.mjs +11 -11
- package/dist/timer.mjs +3 -3
- package/dist/when.mjs +3 -3
- package/package.json +5 -5
- package/src/global.ts +1 -0
- package/types/global.d.ts +1 -1
package/dist/functions.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/functions.ts
|
|
2
2
|
import {
|
|
3
|
-
activeTimers,
|
|
4
|
-
beginTypes,
|
|
5
|
-
endOrRestartTypes,
|
|
6
|
-
endTypes,
|
|
7
|
-
milliseconds
|
|
3
|
+
activeTimers,
|
|
4
|
+
beginTypes,
|
|
5
|
+
endOrRestartTypes,
|
|
6
|
+
endTypes,
|
|
7
|
+
milliseconds
|
|
8
8
|
} from "./constants";
|
|
9
9
|
function getOptions(options, isRepeated) {
|
|
10
10
|
return {
|
package/dist/global.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -319,13 +319,13 @@ class When extends BasicTimer {
|
|
|
319
319
|
// src/index.ts
|
|
320
320
|
document.addEventListener("visibilitychange", () => {
|
|
321
321
|
if (document.hidden) {
|
|
322
|
-
for (const
|
|
323
|
-
hiddenTimers.add(
|
|
324
|
-
|
|
322
|
+
for (const timer2 of activeTimers) {
|
|
323
|
+
hiddenTimers.add(timer2);
|
|
324
|
+
timer2.pause();
|
|
325
325
|
}
|
|
326
326
|
} else {
|
|
327
|
-
for (const
|
|
328
|
-
|
|
327
|
+
for (const timer2 of hiddenTimers) {
|
|
328
|
+
timer2.continue();
|
|
329
329
|
}
|
|
330
330
|
hiddenTimers.clear();
|
|
331
331
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {noop} from "@oscarpalmer/atoms/function";
|
|
3
|
-
import {activeTimers, hiddenTimers} from "./constants";
|
|
2
|
+
import { noop } from "@oscarpalmer/atoms/function";
|
|
3
|
+
import { activeTimers, hiddenTimers } from "./constants";
|
|
4
4
|
import"./global";
|
|
5
|
-
import {wait} from "./timer";
|
|
5
|
+
import { wait } from "./timer";
|
|
6
6
|
function delay(time, timeout) {
|
|
7
7
|
return new Promise((resolve, reject) => {
|
|
8
8
|
const delayed = wait(() => {
|
|
@@ -18,18 +18,18 @@ function delay(time, timeout) {
|
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
import {isRepeated, isTimer, isWaited, isWhen} from "./is";
|
|
22
|
-
import {repeat, wait as wait2} from "./timer";
|
|
23
|
-
import {when} from "./when";
|
|
21
|
+
import { isRepeated, isTimer, isWaited, isWhen } from "./is";
|
|
22
|
+
import { repeat, wait as wait2 } from "./timer";
|
|
23
|
+
import { when } from "./when";
|
|
24
24
|
document.addEventListener("visibilitychange", () => {
|
|
25
25
|
if (document.hidden) {
|
|
26
|
-
for (const
|
|
27
|
-
hiddenTimers.add(
|
|
28
|
-
|
|
26
|
+
for (const timer of activeTimers) {
|
|
27
|
+
hiddenTimers.add(timer);
|
|
28
|
+
timer.pause();
|
|
29
29
|
}
|
|
30
30
|
} else {
|
|
31
|
-
for (const
|
|
32
|
-
|
|
31
|
+
for (const timer of hiddenTimers) {
|
|
32
|
+
timer.continue();
|
|
33
33
|
}
|
|
34
34
|
hiddenTimers.clear();
|
|
35
35
|
}
|
package/dist/timer.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/timer.ts
|
|
2
|
-
import {milliseconds} from "./constants";
|
|
3
|
-
import {getOptions, work} from "./functions";
|
|
2
|
+
import { milliseconds } from "./constants";
|
|
3
|
+
import { getOptions, work } from "./functions";
|
|
4
4
|
import {
|
|
5
|
-
TimerTrace
|
|
5
|
+
TimerTrace
|
|
6
6
|
} from "./models";
|
|
7
7
|
function repeat(callback, options) {
|
|
8
8
|
return timer("repeat", callback, options ?? {}, true);
|
package/dist/when.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/when.ts
|
|
2
|
-
import {noop} from "@oscarpalmer/atoms/function";
|
|
3
|
-
import {BasicTimer, timer
|
|
2
|
+
import { noop } from "@oscarpalmer/atoms/function";
|
|
3
|
+
import { BasicTimer, timer } from "./timer";
|
|
4
4
|
function when(condition, options) {
|
|
5
5
|
let result = false;
|
|
6
6
|
const state = {
|
|
7
7
|
started: false,
|
|
8
|
-
timer:
|
|
8
|
+
timer: timer("repeat", () => {
|
|
9
9
|
if (condition()) {
|
|
10
10
|
result = true;
|
|
11
11
|
state.timer.stop();
|
package/package.json
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
"url": "https://oscarpalmer.se"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@oscarpalmer/atoms": "0.
|
|
7
|
+
"@oscarpalmer/atoms": "0.74.1"
|
|
8
8
|
},
|
|
9
9
|
"description": "A better solution for timeout- and interval-based timers.",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@biomejs/biome": "^1.9.
|
|
11
|
+
"@biomejs/biome": "^1.9.2",
|
|
12
12
|
"@happy-dom/global-registrator": "^15.7.4",
|
|
13
|
-
"@types/bun": "^1.1.
|
|
14
|
-
"bun": "^1.1.
|
|
13
|
+
"@types/bun": "^1.1.10",
|
|
14
|
+
"bun": "^1.1.29",
|
|
15
15
|
"dts-bundle-generator": "9.5.1",
|
|
16
16
|
"typescript": "^5.6.2"
|
|
17
17
|
},
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
},
|
|
51
51
|
"type": "module",
|
|
52
52
|
"types": "types/index.d.cts",
|
|
53
|
-
"version": "0.
|
|
53
|
+
"version": "0.25.0"
|
|
54
54
|
}
|
package/src/global.ts
CHANGED