reactronic 0.22.202 → 0.22.203
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.
|
@@ -4,24 +4,29 @@ export declare abstract class Monitor extends ObservableObject {
|
|
|
4
4
|
abstract readonly isActive: boolean;
|
|
5
5
|
abstract readonly counter: number;
|
|
6
6
|
abstract readonly workers: ReadonlySet<Worker>;
|
|
7
|
-
|
|
7
|
+
abstract readonly duration: number;
|
|
8
|
+
static create(hint: string, activationDelay: number, deactivationDelay: number, durationResolution: number): Monitor;
|
|
8
9
|
}
|
|
9
10
|
export declare class MonitorImpl extends Monitor {
|
|
10
11
|
isActive: boolean;
|
|
11
12
|
counter: number;
|
|
12
13
|
workers: Set<Worker>;
|
|
14
|
+
duration: number;
|
|
13
15
|
internals: {
|
|
16
|
+
started: number;
|
|
14
17
|
activationDelay: number;
|
|
15
18
|
activationTimeout: undefined;
|
|
16
19
|
deactivationDelay: number;
|
|
17
20
|
deactivationTimeout: undefined;
|
|
21
|
+
durationResolution: number;
|
|
18
22
|
};
|
|
19
23
|
enter(worker: Worker): void;
|
|
20
24
|
leave(worker: Worker): void;
|
|
21
|
-
static create(hint: string, activationDelay: number, deactivationDelay: number): MonitorImpl;
|
|
25
|
+
static create(hint: string, activationDelay: number, deactivationDelay: number, durationResolution: number): MonitorImpl;
|
|
22
26
|
static enter(mon: MonitorImpl, worker: Worker): void;
|
|
23
27
|
static leave(mon: MonitorImpl, worker: Worker): void;
|
|
24
28
|
private static doCreate;
|
|
25
29
|
private static activate;
|
|
26
30
|
private static deactivate;
|
|
31
|
+
private static tick;
|
|
27
32
|
}
|
|
@@ -4,8 +4,8 @@ exports.MonitorImpl = exports.Monitor = void 0;
|
|
|
4
4
|
const Hooks_1 = require("./Hooks");
|
|
5
5
|
const Transaction_1 = require("./Transaction");
|
|
6
6
|
class Monitor extends Hooks_1.ObservableObject {
|
|
7
|
-
static create(hint, activationDelay, deactivationDelay) {
|
|
8
|
-
return MonitorImpl.create(hint, activationDelay, deactivationDelay);
|
|
7
|
+
static create(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
8
|
+
return MonitorImpl.create(hint, activationDelay, deactivationDelay, durationResolution);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
exports.Monitor = Monitor;
|
|
@@ -15,11 +15,14 @@ class MonitorImpl extends Monitor {
|
|
|
15
15
|
this.isActive = false;
|
|
16
16
|
this.counter = 0;
|
|
17
17
|
this.workers = new Set();
|
|
18
|
+
this.duration = 0;
|
|
18
19
|
this.internals = {
|
|
20
|
+
started: 0,
|
|
19
21
|
activationDelay: -1,
|
|
20
22
|
activationTimeout: undefined,
|
|
21
23
|
deactivationDelay: -1,
|
|
22
24
|
deactivationTimeout: undefined,
|
|
25
|
+
durationResolution: 1,
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
enter(worker) {
|
|
@@ -34,8 +37,8 @@ class MonitorImpl extends Monitor {
|
|
|
34
37
|
workers.delete(worker);
|
|
35
38
|
MonitorImpl.deactivate(this, this.internals.deactivationDelay);
|
|
36
39
|
}
|
|
37
|
-
static create(hint, activationDelay, deactivationDelay) {
|
|
38
|
-
return Transaction_1.Transaction.run({ hint: 'Monitor.create' }, MonitorImpl.doCreate, hint, activationDelay, deactivationDelay);
|
|
40
|
+
static create(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
41
|
+
return Transaction_1.Transaction.run({ hint: 'Monitor.create' }, MonitorImpl.doCreate, hint, activationDelay, deactivationDelay, durationResolution);
|
|
39
42
|
}
|
|
40
43
|
static enter(mon, worker) {
|
|
41
44
|
mon.enter(worker);
|
|
@@ -43,14 +46,20 @@ class MonitorImpl extends Monitor {
|
|
|
43
46
|
static leave(mon, worker) {
|
|
44
47
|
mon.leave(worker);
|
|
45
48
|
}
|
|
46
|
-
static doCreate(hint, activationDelay, deactivationDelay) {
|
|
49
|
+
static doCreate(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
47
50
|
const m = new MonitorImpl();
|
|
48
51
|
Hooks_1.Hooks.setHint(m, hint);
|
|
49
52
|
m.internals.activationDelay = activationDelay;
|
|
50
53
|
m.internals.deactivationDelay = deactivationDelay;
|
|
54
|
+
m.internals.durationResolution = durationResolution;
|
|
51
55
|
return m;
|
|
52
56
|
}
|
|
53
57
|
static activate(mon, delay) {
|
|
58
|
+
if (mon.internals.started === 0) {
|
|
59
|
+
mon.duration = 0;
|
|
60
|
+
mon.internals.started = performance.now();
|
|
61
|
+
MonitorImpl.tick(mon);
|
|
62
|
+
}
|
|
54
63
|
if (delay >= 0) {
|
|
55
64
|
if (mon.internals.activationTimeout === undefined)
|
|
56
65
|
mon.internals.activationTimeout = setTimeout(() => Transaction_1.Transaction.run({ hint: 'Monitor.activate', standalone: 'isolated' }, MonitorImpl.activate, mon, -1), delay);
|
|
@@ -67,6 +76,22 @@ class MonitorImpl extends Monitor {
|
|
|
67
76
|
mon.isActive = false;
|
|
68
77
|
mon.internals.activationTimeout = undefined;
|
|
69
78
|
}
|
|
79
|
+
if (mon.counter === 0 && mon.internals.started !== 0) {
|
|
80
|
+
const resolution = mon.internals.durationResolution;
|
|
81
|
+
mon.duration = Math.round(resolution * (performance.now() - mon.internals.started)) / resolution;
|
|
82
|
+
mon.internals.started = 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
static tick(mon) {
|
|
86
|
+
if (mon.internals.started !== 0) {
|
|
87
|
+
Transaction_1.Transaction.run(null, () => {
|
|
88
|
+
const resolution = mon.internals.durationResolution;
|
|
89
|
+
mon.duration = Math.round(resolution * (performance.now() - mon.internals.started)) / resolution;
|
|
90
|
+
});
|
|
91
|
+
const t = globalThis !== null && globalThis !== void 0 ? globalThis : global;
|
|
92
|
+
if (t.requestAnimationFrame)
|
|
93
|
+
requestAnimationFrame(() => MonitorImpl.tick(mon));
|
|
94
|
+
}
|
|
70
95
|
}
|
|
71
96
|
}
|
|
72
97
|
exports.MonitorImpl = MonitorImpl;
|