@oscarpalmer/timer 0.30.0 → 0.32.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.cjs +23 -19
- package/dist/constants.js +23 -20
- package/dist/delay.cjs +1 -1
- package/dist/delay.js +2 -2
- package/dist/get.cjs +1 -1
- package/dist/get.js +1 -1
- package/dist/repeat.cjs +1 -2
- package/dist/repeat.js +1 -2
- package/dist/timer.cjs +19 -4
- package/dist/timer.full.js +192 -154
- package/dist/timer.js +19 -4
- package/dist/wait.cjs +1 -2
- package/dist/wait.js +1 -2
- package/dist/when.cjs +66 -63
- package/dist/when.js +66 -63
- package/dist/work.cjs +39 -24
- package/dist/work.js +40 -26
- package/package.json +1 -1
- package/src/constants.ts +36 -27
- package/src/delay.ts +5 -2
- package/src/repeat.ts +1 -2
- package/src/timer.ts +19 -4
- package/src/wait.ts +1 -2
- package/src/when.ts +74 -71
- package/src/work.ts +72 -40
- package/types/constants.d.cts +5 -7
- package/types/constants.d.ts +4 -0
- package/types/index.d.cts +2 -16
- package/types/is.d.cts +18 -15
- package/types/models.d.cts +1 -2
- package/types/repeat.d.cts +1 -8
- package/types/repeat.d.ts +1 -0
- package/types/timer.d.cts +1 -8
- package/types/timer.d.ts +2 -3
- package/types/wait.d.cts +1 -8
- package/types/wait.d.ts +1 -0
- package/types/when.d.cts +1 -81
- package/types/when.d.ts +3 -2
- package/types/work.d.cts +6 -3
- package/types/work.d.ts +1 -0
- package/dist/node_modules/@oscarpalmer/atoms/dist/function.cjs +0 -8
- package/dist/node_modules/@oscarpalmer/atoms/dist/function.js +0 -4
package/dist/constants.cjs
CHANGED
|
@@ -2,25 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
function calculate() {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
const values = [];
|
|
8
|
+
let last;
|
|
9
|
+
function step(now) {
|
|
10
|
+
if (last != null) {
|
|
11
|
+
values.push(now - last);
|
|
12
|
+
}
|
|
13
|
+
last = now;
|
|
14
|
+
if (values.length >= 10) {
|
|
15
|
+
const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - 4);
|
|
16
|
+
resolve(median);
|
|
17
|
+
} else {
|
|
18
|
+
requestAnimationFrame(step);
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
+
requestAnimationFrame(step);
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
const activeTimers = /* @__PURE__ */ new Set();
|
|
23
25
|
const beginTypes = /* @__PURE__ */ new Set(["continue", "start"]);
|
|
26
|
+
const intervalBuffer = 5;
|
|
24
27
|
const destroyedMessage = "Timer has already been destroyed";
|
|
25
28
|
const endTypes = /* @__PURE__ */ new Set(["pause", "stop"]);
|
|
26
29
|
const endOrRestartTypes = /* @__PURE__ */ new Set([
|
|
@@ -31,10 +34,10 @@ const endOrRestartTypes = /* @__PURE__ */ new Set([
|
|
|
31
34
|
const hiddenTimers = /* @__PURE__ */ new Set();
|
|
32
35
|
const pauseTypes = /* @__PURE__ */ new Set(["continue", "pause"]);
|
|
33
36
|
const startedMessage = "Timer has already been started";
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
exports.milliseconds =
|
|
37
|
-
|
|
37
|
+
exports.milliseconds = 1e3 / 60;
|
|
38
|
+
calculate().then((value) => {
|
|
39
|
+
exports.milliseconds = value;
|
|
40
|
+
});
|
|
38
41
|
|
|
39
42
|
exports.activeTimers = activeTimers;
|
|
40
43
|
exports.beginTypes = beginTypes;
|
|
@@ -42,5 +45,6 @@ exports.destroyedMessage = destroyedMessage;
|
|
|
42
45
|
exports.endOrRestartTypes = endOrRestartTypes;
|
|
43
46
|
exports.endTypes = endTypes;
|
|
44
47
|
exports.hiddenTimers = hiddenTimers;
|
|
48
|
+
exports.intervalBuffer = intervalBuffer;
|
|
45
49
|
exports.pauseTypes = pauseTypes;
|
|
46
50
|
exports.startedMessage = startedMessage;
|
package/dist/constants.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
function calculate() {
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
|
+
const values = [];
|
|
4
|
+
let last;
|
|
5
|
+
function step(now) {
|
|
6
|
+
if (last != null) {
|
|
7
|
+
values.push(now - last);
|
|
8
|
+
}
|
|
9
|
+
last = now;
|
|
10
|
+
if (values.length >= 10) {
|
|
11
|
+
const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - 4);
|
|
12
|
+
resolve(median);
|
|
13
|
+
} else {
|
|
14
|
+
requestAnimationFrame(step);
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
+
requestAnimationFrame(step);
|
|
18
|
+
});
|
|
17
19
|
}
|
|
18
20
|
const activeTimers = /* @__PURE__ */ new Set();
|
|
19
21
|
const beginTypes = /* @__PURE__ */ new Set(["continue", "start"]);
|
|
22
|
+
const intervalBuffer = 5;
|
|
20
23
|
const destroyedMessage = "Timer has already been destroyed";
|
|
21
24
|
const endTypes = /* @__PURE__ */ new Set(["pause", "stop"]);
|
|
22
25
|
const endOrRestartTypes = /* @__PURE__ */ new Set([
|
|
@@ -27,9 +30,9 @@ const endOrRestartTypes = /* @__PURE__ */ new Set([
|
|
|
27
30
|
const hiddenTimers = /* @__PURE__ */ new Set();
|
|
28
31
|
const pauseTypes = /* @__PURE__ */ new Set(["continue", "pause"]);
|
|
29
32
|
const startedMessage = "Timer has already been started";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
let milliseconds = 1e3 / 60;
|
|
34
|
+
calculate().then((value) => {
|
|
35
|
+
milliseconds = value;
|
|
36
|
+
});
|
|
34
37
|
|
|
35
|
-
export { activeTimers, beginTypes, destroyedMessage, endOrRestartTypes, endTypes, hiddenTimers, milliseconds, pauseTypes, startedMessage };
|
|
38
|
+
export { activeTimers, beginTypes, destroyedMessage, endOrRestartTypes, endTypes, hiddenTimers, intervalBuffer, milliseconds, pauseTypes, startedMessage };
|
package/dist/delay.cjs
CHANGED
|
@@ -11,7 +11,7 @@ function delay(time) {
|
|
|
11
11
|
let start;
|
|
12
12
|
function step(now) {
|
|
13
13
|
start ??= now;
|
|
14
|
-
if (interval === constants.milliseconds || now - start >= interval -
|
|
14
|
+
if (interval === constants.milliseconds || now - start >= interval - constants.intervalBuffer) {
|
|
15
15
|
resolve();
|
|
16
16
|
} else {
|
|
17
17
|
requestAnimationFrame(step);
|
package/dist/delay.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { milliseconds } from './constants.js';
|
|
1
|
+
import { milliseconds, intervalBuffer } from './constants.js';
|
|
2
2
|
import { getValidNumber } from './get.js';
|
|
3
3
|
|
|
4
4
|
function delay(time) {
|
|
@@ -7,7 +7,7 @@ function delay(time) {
|
|
|
7
7
|
let start;
|
|
8
8
|
function step(now) {
|
|
9
9
|
start ??= now;
|
|
10
|
-
if (interval === milliseconds || now - start >= interval -
|
|
10
|
+
if (interval === milliseconds || now - start >= interval - intervalBuffer) {
|
|
11
11
|
resolve();
|
|
12
12
|
} else {
|
|
13
13
|
requestAnimationFrame(step);
|
package/dist/get.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const _function = require('
|
|
5
|
+
const _function = require('@oscarpalmer/atoms/function');
|
|
6
6
|
|
|
7
7
|
function getCallback(value) {
|
|
8
8
|
return typeof value === "function" ? value : _function.noop;
|
package/dist/get.js
CHANGED
package/dist/repeat.cjs
CHANGED
|
@@ -4,14 +4,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
const constants = require('./constants.cjs');
|
|
6
6
|
const get = require('./get.cjs');
|
|
7
|
+
require('./global.cjs');
|
|
7
8
|
const models = require('./models.cjs');
|
|
8
9
|
const timer = require('./timer.cjs');
|
|
9
|
-
const work = require('./work.cjs');
|
|
10
10
|
|
|
11
11
|
function repeat(callback, options) {
|
|
12
12
|
return new timer.Timer(
|
|
13
13
|
"repeat",
|
|
14
|
-
work.work,
|
|
15
14
|
{
|
|
16
15
|
callback: get.getCallback(callback),
|
|
17
16
|
trace: new models.TimerTrace().stack
|
package/dist/repeat.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { milliseconds } from './constants.js';
|
|
2
2
|
import { getCallback, getValidNumber } from './get.js';
|
|
3
|
+
import './global.js';
|
|
3
4
|
import { TimerTrace } from './models.js';
|
|
4
5
|
import { Timer } from './timer.js';
|
|
5
|
-
import { work } from './work.js';
|
|
6
6
|
|
|
7
7
|
function repeat(callback, options) {
|
|
8
8
|
return new Timer(
|
|
9
9
|
"repeat",
|
|
10
|
-
work,
|
|
11
10
|
{
|
|
12
11
|
callback: getCallback(callback),
|
|
13
12
|
trace: new TimerTrace().stack
|
package/dist/timer.cjs
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
+
const _function = require('@oscarpalmer/atoms/function');
|
|
6
|
+
const work = require('./work.cjs');
|
|
7
|
+
|
|
5
8
|
class Timer {
|
|
6
|
-
constructor(type,
|
|
7
|
-
this.worker = worker;
|
|
9
|
+
constructor(type, state, options, start) {
|
|
8
10
|
this.options = options;
|
|
9
11
|
this.$timer = type;
|
|
10
12
|
this.state = {
|
|
@@ -57,7 +59,20 @@ class Timer {
|
|
|
57
59
|
*/
|
|
58
60
|
destroy() {
|
|
59
61
|
this.state.destroyed = true;
|
|
60
|
-
this
|
|
62
|
+
this.options.onAfter = _function.noop;
|
|
63
|
+
this.options.onError = _function.noop;
|
|
64
|
+
this.state.callback = _function.noop;
|
|
65
|
+
if (!globalThis._oscarpalmer_timer_debug) {
|
|
66
|
+
this.state.trace = void 0;
|
|
67
|
+
}
|
|
68
|
+
work.stop(
|
|
69
|
+
{
|
|
70
|
+
instance: this,
|
|
71
|
+
type: this.$timer
|
|
72
|
+
},
|
|
73
|
+
this.state,
|
|
74
|
+
this.options
|
|
75
|
+
);
|
|
61
76
|
}
|
|
62
77
|
/**
|
|
63
78
|
* Pause the timer _(if it's running)_
|
|
@@ -84,7 +99,7 @@ class Timer {
|
|
|
84
99
|
return this.#work("stop");
|
|
85
100
|
}
|
|
86
101
|
#work(type) {
|
|
87
|
-
return
|
|
102
|
+
return work.work(
|
|
88
103
|
type,
|
|
89
104
|
{
|
|
90
105
|
instance: this,
|