@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.25
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/README.md +1096 -0
- package/dist/api/Raph.d.ts +59 -190
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +9 -4
- package/dist/api/types.d.ts +162 -17
- package/dist/core-CClhT8WR.js +1044 -0
- package/dist/core-cPQWYD4K.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +368 -367
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +302 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +146 -0
- package/dist/debug/api/errors.cjs +1 -1
- package/dist/debug/api/errors.js +10 -7
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/DataPath.js +390 -0
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/PathRouter.js +80 -0
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +316 -236
- package/dist/debug/path/data-path.utils.cjs +1 -0
- package/dist/debug/path/data-path.utils.js +56 -0
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
- package/dist/debug/path/derived/DerivedRegistry.js +143 -0
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
- package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +19 -22
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +71 -71
- package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.types.js +1 -0
- package/dist/debug/path/meta/MetaController.cjs +1 -0
- package/dist/debug/path/{MetaController.js → meta/MetaController.js} +58 -66
- package/dist/debug/path/meta/RaphMeta.cjs +1 -0
- package/dist/debug/path/meta/RaphMeta.js +62 -0
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +24 -30
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/storage/AdapterPathStore.js +128 -0
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +47 -57
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/storage/PathEventHub.js +161 -0
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/{PathStore.js → storage/PathStore.js} +88 -98
- package/dist/debug/path/storage/createDataDraft.cjs +1 -0
- package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +24 -28
- package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
- package/dist/debug/path/storage/data-adapter.types.js +1 -0
- package/dist/debug/reactivity/disposal.cjs +1 -0
- package/dist/debug/reactivity/disposal.js +32 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +888 -321
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +265 -0
- package/dist/debug/reactivity/scope.cjs +1 -1
- package/dist/debug/reactivity/scope.js +221 -117
- package/dist/debug/reactivity/watch.cjs +1 -1
- package/dist/debug/reactivity/watch.js +1 -1
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +1134 -502
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +287 -0
- package/dist/debug/runtime/errors.cjs +1 -1
- package/dist/debug/runtime/errors.js +6 -3
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.js +304 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +665 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +236 -0
- package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
- package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
- package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
- package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +13 -17
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +848 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +176 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.js +20 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/reactivity/PathHandle.js +165 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +108 -0
- package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphSelector.js +503 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +1157 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +550 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +77 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -0
- package/dist/entrypoints/machine.d.ts +5 -0
- package/dist/entrypoints/path.d.ts +14 -0
- package/dist/entrypoints/reactivity.d.ts +1 -0
- package/dist/entrypoints/runtime.d.ts +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -38
- package/dist/machine/compiler.d.ts +71 -0
- package/dist/machine/core.d.ts +50 -0
- package/dist/machine/persistence.d.ts +5 -0
- package/dist/machine/runtime.d.ts +4 -0
- package/dist/machine/testing.d.ts +43 -0
- package/dist/machine/types.d.ts +155 -0
- package/dist/machine-testing.cjs +1 -0
- package/dist/machine-testing.js +188 -0
- package/dist/machine.cjs +1 -0
- package/dist/machine.js +822 -0
- package/dist/main.d.ts +20 -0
- package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
- package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
- package/dist/path/RaphKernel.d.ts +37 -10
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
- package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
- package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
- package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
- package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
- package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
- package/dist/path/path.types.d.ts +3 -2
- package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
- package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
- package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
- package/dist/path/storage/PathEventHub.d.ts +62 -0
- package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +7 -7
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -1
- package/dist/path.js +16 -16
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +46 -38
- package/dist/reactivity/disposal.d.ts +14 -0
- package/dist/reactivity/engine.d.ts +193 -6
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/scope.d.ts +108 -30
- package/dist/reactivity/types.d.ts +25 -0
- package/dist/reactivity.cjs +1 -1
- package/dist/reactivity.js +12 -12
- package/dist/runtime/RaphRuntime.d.ts +319 -160
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +98 -0
- package/dist/runtime/ownership/RaphNode.d.ts +310 -0
- package/dist/runtime/ownership/RaphScope.d.ts +168 -0
- package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +253 -0
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +171 -0
- package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +309 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +293 -0
- package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +12 -6
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +56 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +21 -16
- package/package.json +76 -35
- package/ReadMe.md +0 -153
- package/dist/api/public.d.ts +0 -22
- package/dist/debug/api/public.cjs +0 -1
- package/dist/debug/api/public.js +0 -40
- package/dist/debug/path/AdapterPathStore.cjs +0 -1
- package/dist/debug/path/AdapterPathStore.js +0 -133
- package/dist/debug/path/DerivedRegistry.cjs +0 -1
- package/dist/debug/path/DerivedRegistry.js +0 -157
- package/dist/debug/path/MetaController.cjs +0 -1
- package/dist/debug/path/PathEventHub.cjs +0 -1
- package/dist/debug/path/PathEventHub.js +0 -148
- package/dist/debug/path/PathStore.cjs +0 -1
- package/dist/debug/path/RaphDerivedHandle.cjs +0 -1
- package/dist/debug/path/RaphMeta.cjs +0 -1
- package/dist/debug/path/RaphMeta.js +0 -68
- package/dist/debug/path/RaphMetaStore.cjs +0 -1
- package/dist/debug/path/data-adapter.cjs +0 -1
- package/dist/debug/path/data-draft.cjs +0 -1
- package/dist/debug/path/data-path.cjs +0 -1
- package/dist/debug/path/data-path.js +0 -423
- package/dist/debug/path/derived-collection.cjs +0 -1
- package/dist/debug/path/path-router.cjs +0 -1
- package/dist/debug/path/path-router.js +0 -86
- package/dist/debug/path/public.cjs +0 -1
- package/dist/debug/path/public.js +0 -18
- package/dist/debug/runtime/PathHandle.cjs +0 -1
- package/dist/debug/runtime/PathHandle.js +0 -139
- package/dist/debug/runtime/RaphDebug.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.js +0 -15
- package/dist/debug/runtime/RaphFrameLoop.cjs +0 -1
- package/dist/debug/runtime/RaphNode.cjs +0 -1
- package/dist/debug/runtime/RaphNode.js +0 -143
- package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
- package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
- package/dist/debug/runtime/RaphScope.cjs +0 -1
- package/dist/debug/runtime/RaphScope.js +0 -64
- package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
- package/dist/debug/runtime/RuntimeReactivity.js +0 -154
- package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
- package/dist/debug/runtime/RuntimeWatch.js +0 -71
- package/dist/debug/runtime/public.cjs +0 -1
- package/dist/debug/runtime/public.js +0 -18
- package/dist/path/PathEventHub.d.ts +0 -48
- package/dist/path/public.d.ts +0 -14
- package/dist/runtime/RaphDebug.d.ts +0 -32
- package/dist/runtime/RaphNode.d.ts +0 -68
- package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
- package/dist/runtime/RaphScope.d.ts +0 -50
- package/dist/runtime/RuntimeReactivity.d.ts +0 -40
- package/dist/runtime/phase.types.d.ts +0 -49
- package/dist/runtime/public.d.ts +0 -13
- package/dist/runtime/runtime-reactivity.types.d.ts +0 -9
- /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
- /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
- /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
- /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
- /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
- /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
- /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
- /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
- /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
- /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
- /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
- /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
- /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
- /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
- /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
|
@@ -0,0 +1,848 @@
|
|
|
1
|
+
import { RaphPhaseProcessError as R, RaphDisposedError as I } from "../errors.js";
|
|
2
|
+
import { throwDisposalErrors as z } from "../ownership/throwDisposalErrors.js";
|
|
3
|
+
import { EMPTY_FRAME as B, RaphPhaseTaskRecord as $, GROUP_NODES as y, GROUP_CONTEXT as M, GROUP_CURSOR as N, TASK_ACTIVE as f, TASK_TASKLESS as G, TASK_PENDING as w, TASK_RESOLUTION as b, TASK_UNRESOLVED as j, TASK_CANCEL as m, TASK_RUN as q, TASK_IN_DELIVERY as p, TASK_CAUSES_DELIVERED as k, TASK_EXECUTED as H, TASK_PAUSED as A, TASK_REQUESTED as g, TASK_DEFER as W, TASK_DISCARD_ACKNOWLEDGED as C, TASK_DEFERRED as E } from "./RaphPhaseTaskRecord.js";
|
|
4
|
+
class Q {
|
|
5
|
+
constructor(e, t) {
|
|
6
|
+
this.name = e, this.pipeline = t, this.queue = [], this.spare = [], this.bindings = 0;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const V = 1e4, X = 1e4, P = f | A, x = p | b;
|
|
10
|
+
class te {
|
|
11
|
+
constructor(e, t, s, i = () => !1, a) {
|
|
12
|
+
this._scheduler = e, this._reactivity = t, this._resolveCause = s, this._deferSync = i, this._tracePhase = a;
|
|
13
|
+
}
|
|
14
|
+
_phases = [];
|
|
15
|
+
_phaseByName = /* @__PURE__ */ new Map();
|
|
16
|
+
// Последнее разрешённое имя phase в том виде, в каком его передал вызывающий.
|
|
17
|
+
_resolvedInput;
|
|
18
|
+
_resolvedState;
|
|
19
|
+
// Число записей во всех живых очередях.
|
|
20
|
+
_queuedCount = 0;
|
|
21
|
+
_deferred = /* @__PURE__ */ new Set();
|
|
22
|
+
_idleWaiters = /* @__PURE__ */ new Set();
|
|
23
|
+
_taskSequence = 0;
|
|
24
|
+
_scheduled = !1;
|
|
25
|
+
_scheduleToken = 0;
|
|
26
|
+
_frameHandle;
|
|
27
|
+
_frameHandleKind;
|
|
28
|
+
_configurationLocked = !1;
|
|
29
|
+
/**
|
|
30
|
+
* Flush исполняется сейчас: новая работа попадёт в его следующий проход.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
_running = !1;
|
|
35
|
+
// Значение flags записи slot, которая не запланирована: slot с таким же
|
|
36
|
+
// значением доставка группы пропускает, не обращаясь к engine.
|
|
37
|
+
_idleSlotFlags = -1;
|
|
38
|
+
_disposed = !1;
|
|
39
|
+
_firstFrameAt;
|
|
40
|
+
_lastFrameAt;
|
|
41
|
+
_frameNumber = 0;
|
|
42
|
+
_frame = B;
|
|
43
|
+
get frame() {
|
|
44
|
+
return this._frame;
|
|
45
|
+
}
|
|
46
|
+
get phases() {
|
|
47
|
+
return this._phases.map((e) => e.phase);
|
|
48
|
+
}
|
|
49
|
+
definePhases(e) {
|
|
50
|
+
if (this._assertAlive(), this._configurationLocked || this._firstFrameAt !== void 0)
|
|
51
|
+
throw new Error("[Raph] Cannot redefine phases after phase pipeline execution has started.");
|
|
52
|
+
const t = this._phaseByName, s = /* @__PURE__ */ new Map(), i = [];
|
|
53
|
+
for (const a of e) {
|
|
54
|
+
const n = a.name.trim();
|
|
55
|
+
if (!n)
|
|
56
|
+
throw new Error("[Raph] Phase name must not be empty.");
|
|
57
|
+
if (s.has(n))
|
|
58
|
+
throw new Error(`[Raph] Duplicate phase name "${n}".`);
|
|
59
|
+
if (a.process !== void 0 && typeof a.process != "function")
|
|
60
|
+
throw new TypeError(`[Raph] Phase "${n}" process must be a function.`);
|
|
61
|
+
const o = Object.freeze({
|
|
62
|
+
name: n,
|
|
63
|
+
...a.process === void 0 ? {} : { process: a.process }
|
|
64
|
+
}), r = {
|
|
65
|
+
index: i.length,
|
|
66
|
+
phase: o,
|
|
67
|
+
state: t.get(n)?.state ?? new Q(n, this)
|
|
68
|
+
};
|
|
69
|
+
i.push(r), s.set(n, r);
|
|
70
|
+
}
|
|
71
|
+
this._assertRetainedPhases(s), this._phases = i, this._phaseByName = s, this._resolvedInput = void 0, this._resolvedState = void 0;
|
|
72
|
+
}
|
|
73
|
+
addPhase(e) {
|
|
74
|
+
this.definePhases([...this.phases, e]);
|
|
75
|
+
}
|
|
76
|
+
clearPhases() {
|
|
77
|
+
this.definePhases([]);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Находит состояние объявленной phase по имени, которое передал вызывающий.
|
|
81
|
+
* Подряд идущие bindings одной phase попадают в кэш из одной записи; точное
|
|
82
|
+
* имя находится без `trim()`, и только имя с пробелами по краям нормализуется.
|
|
83
|
+
*/
|
|
84
|
+
resolvePhase(e) {
|
|
85
|
+
this._assertAlive();
|
|
86
|
+
const t = this._resolvedState;
|
|
87
|
+
if (t !== void 0 && e === this._resolvedInput)
|
|
88
|
+
return t;
|
|
89
|
+
let s = this._phaseByName.get(e);
|
|
90
|
+
if (s === void 0) {
|
|
91
|
+
const i = e.trim();
|
|
92
|
+
if (i !== e && (s = this._phaseByName.get(i)), s === void 0)
|
|
93
|
+
throw new Error(`[Raph] Phase "${i}" is not defined.`);
|
|
94
|
+
}
|
|
95
|
+
return this._resolvedInput = e, this._resolvedState = s.state;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Создаёт постоянную запись одного binding. Вызывающий уже разрешил phase
|
|
99
|
+
* и проверил priority, поэтому горячий путь регистрации проверяет их один раз.
|
|
100
|
+
* Запись ничего не выполняет, пока вызывающий не подключит engine effect
|
|
101
|
+
* (`node`) или watch lifecycle (`watch`).
|
|
102
|
+
*/
|
|
103
|
+
bindTask(e, t, s, i) {
|
|
104
|
+
return e.bindings++, new $(e, i, t, s);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Создаёт постоянную запись группы из `count` slots: одна запись binding и
|
|
108
|
+
* её состояние с местом под запись графа каждого slot. Вызывающий уже
|
|
109
|
+
* разрешил phase и проверил priority и `count`; записи графа он подключает
|
|
110
|
+
* сам через _allocateTaskEffect() и кладёт в состояние по порядку slots.
|
|
111
|
+
* Slot ничего не исполняет, пока его запись не запланирована.
|
|
112
|
+
*
|
|
113
|
+
* `runSlot` занимает место callback записи: его показывает `task.effect`
|
|
114
|
+
* группы, а вызывает только общее тело записей engine — с состоянием
|
|
115
|
+
* группы, где лежат её context и номер slot. Поэтому запись группы несёт
|
|
116
|
+
* `TASK_TASKLESS`: вместо task тело получает поле `group`.
|
|
117
|
+
*/
|
|
118
|
+
bindGroup(e, t, s, i, a, n) {
|
|
119
|
+
const o = new Array(y + a);
|
|
120
|
+
o[M] = i, o[N] = 0, e.bindings++;
|
|
121
|
+
const r = new $(e, n, t, s);
|
|
122
|
+
return r.state = f | G, r.group = o, r;
|
|
123
|
+
}
|
|
124
|
+
request() {
|
|
125
|
+
this._assertAlive(), this._queuedCount !== 0 && this._schedule();
|
|
126
|
+
}
|
|
127
|
+
afterFlush() {
|
|
128
|
+
return this._assertAlive(), !this._running && !this._scheduled && !this._hasPending() ? Promise.resolve() : new Promise((e, t) => {
|
|
129
|
+
this._idleWaiters.add({ reject: t, resolve: e });
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
flush() {
|
|
133
|
+
if (this._assertAlive(), this._cancelScheduled(), this._running)
|
|
134
|
+
return;
|
|
135
|
+
if (this._queuedCount === 0 && this._deferred.size !== 0 && this._activateDeferred(), this._queuedCount === 0) {
|
|
136
|
+
this._settleIdleWaiters(void 0, !1);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this._configurationLocked = !0, this._running = !0;
|
|
140
|
+
const e = [], t = this._nextFrame();
|
|
141
|
+
let s = 0, i;
|
|
142
|
+
try {
|
|
143
|
+
for (; this._queuedCount !== 0; ) {
|
|
144
|
+
if (++s > V) {
|
|
145
|
+
const n = this._describeQueued();
|
|
146
|
+
this._cancelAllQueued(!0, e), e.push(new Error(`[Raph] Phase flush exceeded 10000 passes.${n ? ` Pending: ${n}.` : ""}`));
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
for (const n of this._phases) {
|
|
150
|
+
if (this._disposed)
|
|
151
|
+
break;
|
|
152
|
+
const o = n.state, r = o.queue;
|
|
153
|
+
if (r.length === 0)
|
|
154
|
+
continue;
|
|
155
|
+
o.queue = o.spare, o.spare = i = r, this._queuedCount -= r.length;
|
|
156
|
+
const d = e.length;
|
|
157
|
+
this._tracePhase?.(n.phase.name, "start");
|
|
158
|
+
let l = 0, _ = !0, c;
|
|
159
|
+
for (const u of r) {
|
|
160
|
+
const v = u.state;
|
|
161
|
+
if (!(v & f) || u.consumerOwner.disposed) {
|
|
162
|
+
u.state = v & ~w, this._disposeTask(u);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
this._beginDelivery(u, t), c !== void 0 && (u.priority > c.priority || u.priority === c.priority && u.sequence < c.sequence) && (_ = !1), c = u, r[l++] = u;
|
|
166
|
+
}
|
|
167
|
+
if (r.length = l, r.length === 0) {
|
|
168
|
+
i = void 0;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
_ || r.sort(Y);
|
|
172
|
+
const D = n.phase.process;
|
|
173
|
+
if (D === void 0)
|
|
174
|
+
for (const u of r)
|
|
175
|
+
try {
|
|
176
|
+
this._runDelivery(u, e);
|
|
177
|
+
} catch (v) {
|
|
178
|
+
e.push(v);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const u = [];
|
|
182
|
+
for (const K of r)
|
|
183
|
+
u.push(K.task);
|
|
184
|
+
const v = Object.freeze({
|
|
185
|
+
phase: n.phase.name,
|
|
186
|
+
frame: t,
|
|
187
|
+
tasks: Object.freeze(u)
|
|
188
|
+
});
|
|
189
|
+
try {
|
|
190
|
+
this._reactivity.untrackedWithOwner(() => D(v));
|
|
191
|
+
} catch (K) {
|
|
192
|
+
e.push(K);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
let T = 0;
|
|
196
|
+
for (const u of r) {
|
|
197
|
+
if ((u.state & b) === j) {
|
|
198
|
+
T++;
|
|
199
|
+
try {
|
|
200
|
+
this._deferDelivery(u);
|
|
201
|
+
} catch (v) {
|
|
202
|
+
u.state |= m, this._acknowledgeDiscard(u, !0, e), e.push(v);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
this._finishDelivery(u);
|
|
207
|
+
} catch (v) {
|
|
208
|
+
(u.state & b) !== q && this._acknowledgeDiscard(u, !0, e), u.state = (u.state | m) & ~p, S(u), e.push(v);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
r.length = 0, i = void 0, T !== 0 && e.push(new R(
|
|
212
|
+
`[Raph] Phase "${n.phase.name}" left ${T} task(s) unresolved; they were deferred.`
|
|
213
|
+
)), e.length === d ? this._tracePhase?.(n.phase.name, "end") : this._tracePhase?.(
|
|
214
|
+
n.phase.name,
|
|
215
|
+
"error",
|
|
216
|
+
e[e.length - 1]
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} catch (n) {
|
|
221
|
+
e.push(n), i !== void 0 && (i.length = 0), this._cancelAllQueued(!0, e), this._cancelAllDeferred(!0, e);
|
|
222
|
+
} finally {
|
|
223
|
+
this._running = !1;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
this._deferred.size !== 0 && this._scheduleDeferredTurn();
|
|
227
|
+
} catch (n) {
|
|
228
|
+
e.push(n);
|
|
229
|
+
}
|
|
230
|
+
const a = e.length === 1 ? e[0] : e.length > 1 ? new AggregateError(e, "[Raph] Multiple phase tasks failed.") : void 0;
|
|
231
|
+
if (e.length !== 0)
|
|
232
|
+
throw this._settleIdleWaiters(a, !0), a;
|
|
233
|
+
this._settleIdleWaiters(void 0, !1);
|
|
234
|
+
}
|
|
235
|
+
dispose() {
|
|
236
|
+
if (this._disposed)
|
|
237
|
+
return;
|
|
238
|
+
this._disposed = !0, this._cancelScheduled(), this._cancelAllQueued(!1);
|
|
239
|
+
const e = [...this._deferred];
|
|
240
|
+
this._cancelAllDeferred(!1);
|
|
241
|
+
for (const s of e)
|
|
242
|
+
s.state &= ~f;
|
|
243
|
+
this._phases = [], this._phaseByName.clear(), this._resolvedInput = void 0, this._resolvedState = void 0;
|
|
244
|
+
const t = new I("[Raph] Phase pipeline is disposed.");
|
|
245
|
+
this._settleIdleWaiters(t, !0);
|
|
246
|
+
}
|
|
247
|
+
_debugPending() {
|
|
248
|
+
return this._scheduled || this._running || this._hasPending();
|
|
249
|
+
}
|
|
250
|
+
_describeQueued() {
|
|
251
|
+
const e = [];
|
|
252
|
+
for (const t of this._phases) {
|
|
253
|
+
const s = t.state.queue.filter(
|
|
254
|
+
(a) => (a.state & f) !== 0 && !a.consumerOwner.disposed
|
|
255
|
+
);
|
|
256
|
+
if (s.length === 0)
|
|
257
|
+
continue;
|
|
258
|
+
const i = s.slice(0, 3).map((a) => {
|
|
259
|
+
const n = a.consumerOwner.node, o = n === void 0 ? void 0 : n.componentId, r = n === void 0 ? a.consumerOwner.id : `${a.consumerOwner.id}/${n.constructor.name}/${n.type}${typeof o == "string" ? `/${o}` : ""}`, d = a.firstCause?.sourceOwner?.node, l = d === void 0 ? "" : `<=${d.id}/${d.constructor.name}`;
|
|
260
|
+
return `${r}${a.firstCause ? `:${a.firstCause.kind}${l}` : ""}`;
|
|
261
|
+
}).join(", ");
|
|
262
|
+
e.push(`${t.phase.name}=${s.length}${i ? ` [${i}]` : ""}`);
|
|
263
|
+
}
|
|
264
|
+
return e.join("; ");
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Открывает доставку одной записью `state`. Накопленные причины остаются на
|
|
268
|
+
* своих местах и становятся причинами доставки под TASK_CAUSES_DELIVERED:
|
|
269
|
+
* ничего не копируется, а массив для `task.causes` строится, только если его
|
|
270
|
+
* прочитают. Frame доставки получает только запись с facade: без facade его
|
|
271
|
+
* нечем прочитать, а запись ссылки на новый frame в каждую доставленную
|
|
272
|
+
* запись стоит write barrier.
|
|
273
|
+
*
|
|
274
|
+
* Запись попадает сюда только из живой очереди, а в ней нет записей с
|
|
275
|
+
* открытой доставкой, поэтому причин прошлой доставки здесь не бывает.
|
|
276
|
+
*/
|
|
277
|
+
_beginDelivery(e, t) {
|
|
278
|
+
const s = e.state & -1893 | p;
|
|
279
|
+
e.state = e.firstCause === void 0 ? s : s | k, e.facade !== void 0 && (e.frame = t);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Исполняет открытую доставку binding. `failures` передаёт default runner:
|
|
283
|
+
* группа складывает туда сбой каждого slot отдельно. Без него сбои slots
|
|
284
|
+
* бросаются вызывающему — `task.run()` внутри `process` — после прохода: один
|
|
285
|
+
* как есть, несколько одним AggregateError.
|
|
286
|
+
*
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
_runDelivery(e, t) {
|
|
290
|
+
const s = e.state;
|
|
291
|
+
if ((s & P) !== f || e.consumerOwner.disposed) {
|
|
292
|
+
e.state = s | m;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
(s & x) !== p && O(), e.state = s | q;
|
|
296
|
+
const i = e.detail;
|
|
297
|
+
i !== void 0 && (i.deferCount = 0);
|
|
298
|
+
const a = this._reactivity, n = e.node;
|
|
299
|
+
if (n !== void 0) {
|
|
300
|
+
a._beginTaskEffectRun(n) && (e.state |= H, a._runTaskEffectUntracked(n));
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const o = e.group;
|
|
304
|
+
if (o === void 0) {
|
|
305
|
+
const _ = e.watch;
|
|
306
|
+
_ !== void 0 && a.untrackedWithOwner(_.deliver);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const r = o.length;
|
|
310
|
+
let d = this._idleSlotFlags, l;
|
|
311
|
+
for (let _ = y; _ < r; _++) {
|
|
312
|
+
const c = o[_];
|
|
313
|
+
if (c === null || c.flags === d)
|
|
314
|
+
continue;
|
|
315
|
+
if (!a._beginTaskEffectRun(c)) {
|
|
316
|
+
c.evaluate !== void 0 && (this._idleSlotFlags = d = c.flags);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
o[N] = _ - y;
|
|
320
|
+
try {
|
|
321
|
+
a._runTaskEffectUntracked(c);
|
|
322
|
+
} catch (T) {
|
|
323
|
+
t !== void 0 ? t.push(T) : (l ??= []).push(T);
|
|
324
|
+
}
|
|
325
|
+
const D = e.state;
|
|
326
|
+
if (!(D & f))
|
|
327
|
+
break;
|
|
328
|
+
if (D & A) {
|
|
329
|
+
_ + 1 < r && (this._restoreDeliveryCausesBeforePending(e), e.state |= g);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (l !== void 0)
|
|
334
|
+
throw l.length === 1 ? l[0] : new AggregateError(l, "[Raph] Effect group delivery failed.");
|
|
335
|
+
}
|
|
336
|
+
/** @internal */
|
|
337
|
+
_deferDelivery(e) {
|
|
338
|
+
const t = e.state;
|
|
339
|
+
if ((t & P) !== f || e.consumerOwner.disposed) {
|
|
340
|
+
e.state = t | m;
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if ((t & x) !== p && O(), e.state = t | W, ++e.detailed().deferCount > X) {
|
|
344
|
+
e.state |= m;
|
|
345
|
+
const s = [];
|
|
346
|
+
throw this._acknowledgeDiscard(e, !0, s), s.length !== 0 ? new AggregateError(
|
|
347
|
+
[new R(
|
|
348
|
+
`[Raph] Phase task in "${e.phase}" exceeded 10000 deferred deliveries.`
|
|
349
|
+
), ...s],
|
|
350
|
+
"[Raph] Phase task defer limit and recovery failed."
|
|
351
|
+
) : new R(
|
|
352
|
+
`[Raph] Phase task in "${e.phase}" exceeded 10000 deferred deliveries.`
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/** @internal */
|
|
357
|
+
_cancelDelivery(e) {
|
|
358
|
+
const t = e.state;
|
|
359
|
+
if (!(t & f) || e.consumerOwner.disposed) {
|
|
360
|
+
e.state = t | m;
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
(t & x) !== p && O();
|
|
364
|
+
const s = [];
|
|
365
|
+
if (this._acknowledgeDiscard(e, !1, s), s.length !== 0)
|
|
366
|
+
throw s.length === 1 ? s[0] : new AggregateError(s, "[Raph] Phase task cancellation failed.");
|
|
367
|
+
let i = e.state | m;
|
|
368
|
+
i & C && (i = F(e) ? i | g : i & ~g), e.state = i;
|
|
369
|
+
const a = e.detail;
|
|
370
|
+
a !== void 0 && (a.deferCount = 0);
|
|
371
|
+
}
|
|
372
|
+
_finishDelivery(e) {
|
|
373
|
+
const t = e.state;
|
|
374
|
+
if (!(t & p))
|
|
375
|
+
return;
|
|
376
|
+
const s = t & b;
|
|
377
|
+
if (e.state = t & ~p, !(t & f) || e.consumerOwner.disposed) {
|
|
378
|
+
S(e);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (t & A) {
|
|
382
|
+
s !== q && !(s === m && (t & C) !== 0) && (this._restoreDeliveryCausesBeforePending(e), e.state |= g), S(e);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (s === W) {
|
|
386
|
+
this._restoreDeliveryCausesBeforePending(e), e.state |= E, this._deferred.add(e), S(e);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (S(e), (e.state & g) !== 0 || e.firstCause !== void 0) {
|
|
390
|
+
const i = e.node;
|
|
391
|
+
if (i !== void 0)
|
|
392
|
+
this._reactivity._rearmTaskEffect(i);
|
|
393
|
+
else {
|
|
394
|
+
const a = e.group;
|
|
395
|
+
a !== void 0 && this._rearmGroup(a), this._queue(e);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Делает исполняемыми slots группы, которые остались запланированными после
|
|
401
|
+
* доставки: slot, изменивший собственную зависимость, и slot, чью зависимость
|
|
402
|
+
* изменили после его запуска. Slot, который не запланирован, не трогается:
|
|
403
|
+
* он уже прочитал актуальные значения и в следующей доставке не исполняется.
|
|
404
|
+
* Запись, сделанную до запуска slot в той же доставке, slot читает в ней же:
|
|
405
|
+
* прямую запись engine переводит в обязательный запуск, отложенную находит
|
|
406
|
+
* проверка зависимостей. Отдельный binding после такой записи исполняется
|
|
407
|
+
* ещё раз следующим проходом; slot повторно не исполняется.
|
|
408
|
+
*
|
|
409
|
+
* Запись без зависимостей пропускается. Запланированной она бывает в двух
|
|
410
|
+
* случаях: slot запущен во время доставки и ждёт первого запуска — тогда она
|
|
411
|
+
* исполняема с момента создания; либо повторно запущен slot, который уже
|
|
412
|
+
* исполнился и ничего не прочитал, — тогда исполнять его нечем.
|
|
413
|
+
*/
|
|
414
|
+
_rearmGroup(e) {
|
|
415
|
+
const t = this._reactivity;
|
|
416
|
+
for (let s = y; s < e.length; s++) {
|
|
417
|
+
const i = e[s];
|
|
418
|
+
i !== null && i.firstDep !== null && t._beginTaskEffectRun(i) && t._rearmTaskEffect(i);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/** @internal */
|
|
422
|
+
_notifyTask(e, t) {
|
|
423
|
+
const s = this._resolveCause(t);
|
|
424
|
+
if (s !== void 0) {
|
|
425
|
+
const i = s.kind === "structure" ? s.source : t;
|
|
426
|
+
this._appendCause(e, s, i);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/** @internal */
|
|
430
|
+
_appendCause(e, t, s) {
|
|
431
|
+
const i = e.state;
|
|
432
|
+
if (!(i & f))
|
|
433
|
+
return;
|
|
434
|
+
i & k && this._splitDeliveredCauses(e);
|
|
435
|
+
const a = e.firstCause;
|
|
436
|
+
if (a === void 0) {
|
|
437
|
+
e.firstCause = t, e.firstCauseKey = s;
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (e.firstCauseKey === s) {
|
|
441
|
+
e.firstCause = U(a, t);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const n = e.detailed().extraCauses ??= /* @__PURE__ */ new Map(), o = n.get(s);
|
|
445
|
+
n.set(s, o === void 0 ? t : U(o, t));
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Переносит причины открытой доставки с места ожидающих в detail, без
|
|
449
|
+
* копирования, и освобождает это место. После вызова запись хранит оба
|
|
450
|
+
* набора раздельно: ожидающие причины — в своих полях, причины доставки — в
|
|
451
|
+
* detail. Массив, уже построенный для `task.causes`, остаётся тем же.
|
|
452
|
+
*/
|
|
453
|
+
_splitDeliveredCauses(e) {
|
|
454
|
+
const t = e.detailed(), s = t.extraCauses;
|
|
455
|
+
t.deliveryFirstCause = e.firstCause, t.deliveryFirstCauseKey = e.firstCauseKey, t.deliveryExtraCauses = s === void 0 || s.size === 0 ? void 0 : s, t.extraCauses = void 0, e.firstCause = void 0, e.firstCauseKey = void 0, e.state &= ~k;
|
|
456
|
+
}
|
|
457
|
+
/** @internal */
|
|
458
|
+
_queue(e, t = !0) {
|
|
459
|
+
const s = e.state;
|
|
460
|
+
if (!(!(s & f) || e.consumerOwner.disposed || this._disposed)) {
|
|
461
|
+
if (s & (A | p)) {
|
|
462
|
+
e.state = s | g;
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (s & w) {
|
|
466
|
+
t && this._schedule();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
s & E || (e.state = s & ~C | w, e.sequence = this._taskSequence++, e.phaseState.queue.push(e), this._queuedCount++, t && this._schedule());
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/** @internal */
|
|
473
|
+
_disposeTask(e) {
|
|
474
|
+
const t = e.state;
|
|
475
|
+
if (!(t & f))
|
|
476
|
+
return;
|
|
477
|
+
const s = t & -270;
|
|
478
|
+
e.state = t & p ? s | m : s, e.firstCause = void 0, e.firstCauseKey = void 0;
|
|
479
|
+
const i = e.detail;
|
|
480
|
+
i !== void 0 && (i.extraCauses?.clear(), i.extraCauses = void 0, L(i)), t & E && this._deferred.delete(e), t & w && this._unqueue(e), e.phaseState.bindings--, this._hasPending() || this._cancelScheduled(), this._settleIdleWaiters(void 0, !1);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Полностью освобождает один binding; каждый шаг идемпотентен, поэтому
|
|
484
|
+
* владелец, engine и пользователь могут прийти сюда в любом порядке и
|
|
485
|
+
* повторно войти в метод.
|
|
486
|
+
*
|
|
487
|
+
* @internal
|
|
488
|
+
*/
|
|
489
|
+
_disposeBinding(e) {
|
|
490
|
+
const t = e.group;
|
|
491
|
+
if (t !== void 0 && this._forgetStoppedSlots(t))
|
|
492
|
+
return;
|
|
493
|
+
e.scopeParent !== void 0 && e.consumerOwner._releaseRecord(e);
|
|
494
|
+
const s = e.node;
|
|
495
|
+
if (s !== void 0)
|
|
496
|
+
e.node = void 0, this._reactivity._disposeTaskEffect(s);
|
|
497
|
+
else {
|
|
498
|
+
if (t !== void 0) {
|
|
499
|
+
e.group = void 0, this._disposeGroup(e, t);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const i = e.watch;
|
|
503
|
+
i !== void 0 && (e.watch = void 0, i.stop(() => this._releaseWatch(e, i)));
|
|
504
|
+
}
|
|
505
|
+
this._disposeTask(e);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Убирает из состояния группы slots, записи графа которых уже остановлены, и
|
|
509
|
+
* сообщает, остались ли при этом живые slots.
|
|
510
|
+
*
|
|
511
|
+
* Запись одного slot останавливается отдельно от группы в трёх случаях: упал
|
|
512
|
+
* cleanup перед повторным запуском slot; перезапускается или останавливается
|
|
513
|
+
* effect, внутри тела которого группа зарегистрирована; провалился запуск
|
|
514
|
+
* slot через `start()`. Engine сообщает о каждой такой остановке через task
|
|
515
|
+
* hook, общий для всех slots, и запись в этот момент уже остановлена. Группа
|
|
516
|
+
* тогда теряет только этот slot, как owner потерял бы один из отдельных
|
|
517
|
+
* bindings; запись binding освобождается, когда остановлен последний slot.
|
|
518
|
+
*
|
|
519
|
+
* Вызов владельца или effect scope остановленных записей не находит: место
|
|
520
|
+
* остановленного slot уже занято `null`.
|
|
521
|
+
*
|
|
522
|
+
* @returns true, если вызов был сообщением engine и живые slots остались.
|
|
523
|
+
*/
|
|
524
|
+
_forgetStoppedSlots(e) {
|
|
525
|
+
let t = !1, s = !1;
|
|
526
|
+
for (let i = y; i < e.length; i++) {
|
|
527
|
+
const a = e[i];
|
|
528
|
+
a != null && (a.evaluate === void 0 ? (e[i] = null, t = !0) : s = !0);
|
|
529
|
+
}
|
|
530
|
+
return t && s;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Останавливает записи графа всех slots группы в порядке, обратном порядку
|
|
534
|
+
* slots: так владелец освобождал бы отдельные bindings. Сбой cleanup одного
|
|
535
|
+
* slot не мешает остановить остальные.
|
|
536
|
+
*
|
|
537
|
+
* Группа — один ресурс, поэтому порядок и вид ошибки не зависят от того, кто
|
|
538
|
+
* её освобождает. Effect scope отдельные bindings освободил бы в порядке
|
|
539
|
+
* регистрации и сложил бы их сбои в собственный список; группу он
|
|
540
|
+
* освобождает в обратном порядке slots и получает несколько сбоев одним
|
|
541
|
+
* AggregateError. Владелец получает тот же AggregateError как один сбой
|
|
542
|
+
* ресурса вместо отдельных сбоев bindings.
|
|
543
|
+
*
|
|
544
|
+
* Остановка первой же записи повторно входит в _disposeBinding() через task
|
|
545
|
+
* hook engine: вложенный вызов уже не находит состояния группы и освобождает
|
|
546
|
+
* состояние pipeline до cleanup slots. Группа без живых slots освобождает
|
|
547
|
+
* его здесь.
|
|
548
|
+
*/
|
|
549
|
+
_disposeGroup(e, t) {
|
|
550
|
+
const s = this._reactivity;
|
|
551
|
+
let i;
|
|
552
|
+
for (let a = t.length - 1; a >= y; a--) {
|
|
553
|
+
const n = t[a];
|
|
554
|
+
if (n != null)
|
|
555
|
+
try {
|
|
556
|
+
s._disposeTaskEffect(n);
|
|
557
|
+
} catch (o) {
|
|
558
|
+
(i ??= []).push(o);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
this._disposeTask(e);
|
|
563
|
+
} catch (a) {
|
|
564
|
+
(i ??= []).push(a);
|
|
565
|
+
}
|
|
566
|
+
if (i !== void 0)
|
|
567
|
+
throw i.length === 1 ? i[0] : new AggregateError(i, "[Raph] Effect group disposal failed.");
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Освобождает подписку и состояние pipeline остановленного watch.
|
|
571
|
+
*/
|
|
572
|
+
_releaseWatch(e, t) {
|
|
573
|
+
const s = [], i = t.source;
|
|
574
|
+
if (t.source = void 0, t.record = void 0, i !== void 0)
|
|
575
|
+
try {
|
|
576
|
+
i();
|
|
577
|
+
} catch (a) {
|
|
578
|
+
s.push(a);
|
|
579
|
+
}
|
|
580
|
+
try {
|
|
581
|
+
this._disposeTask(e);
|
|
582
|
+
} catch (a) {
|
|
583
|
+
s.push(a);
|
|
584
|
+
}
|
|
585
|
+
z(s, "[Raph] Phase watch disposal failed.");
|
|
586
|
+
}
|
|
587
|
+
/** @internal */
|
|
588
|
+
_pauseTask(e) {
|
|
589
|
+
const t = e.state;
|
|
590
|
+
if ((t & P) !== f)
|
|
591
|
+
return;
|
|
592
|
+
const s = t & b, i = (t | A) & -13;
|
|
593
|
+
e.state = (t & (w | E)) !== 0 || (t & p) !== 0 && s !== q && !(s === m && (t & C) !== 0) ? i | g : i, t & E && this._deferred.delete(e), t & w && this._unqueue(e), this._hasPending() || this._cancelScheduled(), this._settleIdleWaiters(void 0, !1);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Убирает ожидающую запись из живой очереди её phase. Запись, которую flush
|
|
597
|
+
* уже забрал на разбор, в живой очереди не находится и счётчик не меняет.
|
|
598
|
+
*/
|
|
599
|
+
_unqueue(e) {
|
|
600
|
+
const t = e.phaseState.queue, s = t.indexOf(e);
|
|
601
|
+
s >= 0 && (t.splice(s, 1), this._queuedCount--);
|
|
602
|
+
}
|
|
603
|
+
/** @internal */
|
|
604
|
+
_resumeTask(e) {
|
|
605
|
+
const t = e.state;
|
|
606
|
+
(t & P) !== P || e.consumerOwner.disposed || ((t & g) !== 0 || F(e) ? (e.state = t & -67, this._queue(e)) : e.state = t & ~A);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Возвращает причины открытой доставки в ожидающие, впереди причин, которые
|
|
610
|
+
* пришли после её открытия; причины одного source сливаются. Причины доставки
|
|
611
|
+
* при этом остаются причинами доставки до её конца, поэтому сначала они
|
|
612
|
+
* отделяются от ожидающих.
|
|
613
|
+
*/
|
|
614
|
+
_restoreDeliveryCausesBeforePending(e) {
|
|
615
|
+
e.state & k && this._splitDeliveredCauses(e);
|
|
616
|
+
const t = e.detail;
|
|
617
|
+
if (t === void 0)
|
|
618
|
+
return;
|
|
619
|
+
const s = t.deliveryFirstCause;
|
|
620
|
+
if (s === void 0)
|
|
621
|
+
return;
|
|
622
|
+
const i = e.firstCause, a = e.firstCauseKey, n = t.extraCauses;
|
|
623
|
+
e.firstCause = void 0, e.firstCauseKey = void 0, t.extraCauses = void 0, this._appendCause(e, s, t.deliveryFirstCauseKey);
|
|
624
|
+
const o = t.deliveryExtraCauses;
|
|
625
|
+
if (o !== void 0)
|
|
626
|
+
for (const [r, d] of o)
|
|
627
|
+
this._appendCause(e, d, r);
|
|
628
|
+
if (i !== void 0 && (this._appendCause(e, i, a), n !== void 0))
|
|
629
|
+
for (const [r, d] of n)
|
|
630
|
+
this._appendCause(e, d, r);
|
|
631
|
+
}
|
|
632
|
+
_schedule() {
|
|
633
|
+
if (this._running || this._scheduled || this._disposed)
|
|
634
|
+
return;
|
|
635
|
+
if (this._scheduler === "sync") {
|
|
636
|
+
if (this._deferSync())
|
|
637
|
+
return;
|
|
638
|
+
this.flush();
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
this._scheduled = !0;
|
|
642
|
+
const e = ++this._scheduleToken, t = () => {
|
|
643
|
+
this._disposed || !this._scheduled || e !== this._scheduleToken || (this._scheduled = !1, this._frameHandle = void 0, this._frameHandleKind = void 0, this.flush());
|
|
644
|
+
};
|
|
645
|
+
if (this._scheduler === "microtask") {
|
|
646
|
+
queueMicrotask(t);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
typeof globalThis.requestAnimationFrame == "function" ? (this._frameHandleKind = "animation-frame", this._frameHandle = globalThis.requestAnimationFrame(t)) : (this._frameHandleKind = "timeout", this._frameHandle = setTimeout(t, 16));
|
|
650
|
+
}
|
|
651
|
+
_scheduleDeferredTurn() {
|
|
652
|
+
if (this._scheduled || this._disposed)
|
|
653
|
+
return;
|
|
654
|
+
this._scheduled = !0;
|
|
655
|
+
const e = ++this._scheduleToken, t = () => {
|
|
656
|
+
this._disposed || !this._scheduled || e !== this._scheduleToken || (this._scheduled = !1, this._frameHandle = void 0, this._frameHandleKind = void 0, this._activateDeferred(), this._queuedCount !== 0 ? this.flush() : this._settleIdleWaiters(void 0, !1));
|
|
657
|
+
};
|
|
658
|
+
this._scheduler === "animationFrame" ? typeof globalThis.requestAnimationFrame == "function" ? (this._frameHandleKind = "animation-frame", this._frameHandle = globalThis.requestAnimationFrame(t)) : (this._frameHandleKind = "timeout", this._frameHandle = setTimeout(t, 16)) : queueMicrotask(t);
|
|
659
|
+
}
|
|
660
|
+
_cancelScheduled() {
|
|
661
|
+
this._scheduled && (this._scheduled = !1, this._scheduleToken++, this._frameHandleKind === "animation-frame" && this._frameHandle !== void 0 ? globalThis.cancelAnimationFrame?.(this._frameHandle) : this._frameHandleKind === "timeout" && this._frameHandle !== void 0 && clearTimeout(this._frameHandle), this._frameHandle = void 0, this._frameHandleKind = void 0);
|
|
662
|
+
}
|
|
663
|
+
_activateDeferred() {
|
|
664
|
+
const e = [...this._deferred];
|
|
665
|
+
this._deferred.clear();
|
|
666
|
+
for (const t of e)
|
|
667
|
+
t.state &= ~E, this._queue(t, !1);
|
|
668
|
+
}
|
|
669
|
+
_nextFrame() {
|
|
670
|
+
const e = globalThis.performance?.now() ?? Date.now();
|
|
671
|
+
if (this._firstFrameAt === void 0 || this._lastFrameAt === void 0)
|
|
672
|
+
return this._firstFrameAt = e, this._lastFrameAt = e, this._frame = Object.freeze({ now: e, delta: 0, elapsed: 0, frame: 0 });
|
|
673
|
+
this._frameNumber++;
|
|
674
|
+
const t = Object.freeze({
|
|
675
|
+
now: e,
|
|
676
|
+
delta: Math.min(Math.max(e - this._lastFrameAt, 0), 100),
|
|
677
|
+
elapsed: Math.max(e - this._firstFrameAt, 0),
|
|
678
|
+
frame: this._frameNumber
|
|
679
|
+
});
|
|
680
|
+
return this._lastFrameAt = e, this._frame = t;
|
|
681
|
+
}
|
|
682
|
+
_assertRetainedPhases(e) {
|
|
683
|
+
for (const t of this._phases) {
|
|
684
|
+
const s = t.state;
|
|
685
|
+
if (s.bindings !== 0 && !e.has(s.name))
|
|
686
|
+
throw new Error(`[Raph] Cannot remove phase "${s.name}" while it is still bound.`);
|
|
687
|
+
}
|
|
688
|
+
for (const t of this._phases) {
|
|
689
|
+
const s = t.state;
|
|
690
|
+
if (s.queue.length !== 0 && !e.has(s.name))
|
|
691
|
+
throw new Error(`[Raph] Cannot remove phase "${s.name}" while it has pending work.`);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
_hasPending() {
|
|
695
|
+
return this._queuedCount !== 0 || this._deferred.size !== 0;
|
|
696
|
+
}
|
|
697
|
+
_cancelAllQueued(e, t = []) {
|
|
698
|
+
if (this._queuedCount === 0)
|
|
699
|
+
return;
|
|
700
|
+
const s = [];
|
|
701
|
+
for (const i of this._phases) {
|
|
702
|
+
const a = i.state.queue;
|
|
703
|
+
for (const n of a)
|
|
704
|
+
s.push(n);
|
|
705
|
+
a.length = 0;
|
|
706
|
+
}
|
|
707
|
+
this._queuedCount = 0;
|
|
708
|
+
for (const i of s)
|
|
709
|
+
i.state &= ~w, e && this._acknowledgeDiscard(i, !0, t), this._clearPendingDelivery(i);
|
|
710
|
+
}
|
|
711
|
+
_cancelAllDeferred(e, t = []) {
|
|
712
|
+
const s = [...this._deferred];
|
|
713
|
+
this._deferred.clear();
|
|
714
|
+
for (const i of s)
|
|
715
|
+
i.state &= ~E, e && this._acknowledgeDiscard(i, !0, t), this._clearPendingDelivery(i);
|
|
716
|
+
}
|
|
717
|
+
_acknowledgeDiscard(e, t, s) {
|
|
718
|
+
const i = e.state;
|
|
719
|
+
if (i & C)
|
|
720
|
+
return;
|
|
721
|
+
const a = e.node, n = e.group;
|
|
722
|
+
if (a === void 0 && n === void 0 || !(i & f)) {
|
|
723
|
+
e.state = i | C;
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
try {
|
|
727
|
+
if (a !== void 0 ? (i & H) !== 0 && this._reactivity._cancelTaskEffect(a) : this._cancelGroup(e, n, t)) {
|
|
728
|
+
e.state |= C;
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
if (!t) {
|
|
732
|
+
s.push(new R(
|
|
733
|
+
`[Raph] Initial effect delivery in "${e.phase}" cannot be cancelled before dependency collection.`
|
|
734
|
+
));
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
e.dispose(), e.state |= C;
|
|
738
|
+
} catch (o) {
|
|
739
|
+
s.push(o);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Гасит ожидающую доставку slots группы.
|
|
744
|
+
*
|
|
745
|
+
* Slot, чей первый запуск ещё впереди, погасить нельзя: он не собрал
|
|
746
|
+
* зависимости, и после отмены его ничто не разбудит. Такой slot узнаётся по
|
|
747
|
+
* запланированной записи без единой зависимости: запись, которая уже
|
|
748
|
+
* исполнялась и ничего не прочитала, больше не планируется. Обычная отмена
|
|
749
|
+
* тогда не трогает ни один slot и возвращает false; fatal discard
|
|
750
|
+
* останавливает такие slots окончательно и гасит остальные.
|
|
751
|
+
*
|
|
752
|
+
* Обычная отмена отказывается только от того, что доставка знала при
|
|
753
|
+
* открытии. Причина, пришедшая группе после открытия доставки, означает
|
|
754
|
+
* запись, которую запланированный slot ещё не прочитал. Гашение снимает с
|
|
755
|
+
* записи slot и отметку планирования, и требование запуска, которое engine
|
|
756
|
+
* поставил при прямой записи, поэтому slots, ждавшие запуска, после гашения
|
|
757
|
+
* снова требуют его, как отдельный binding, отменённый при новой причине.
|
|
758
|
+
* Группа тогда доставляется ещё раз с новыми причинами. Fatal discard гасит
|
|
759
|
+
* всё.
|
|
760
|
+
*
|
|
761
|
+
* @returns false, если доставку нельзя отменить либо живых slots не осталось.
|
|
762
|
+
*/
|
|
763
|
+
_cancelGroup(e, t, s) {
|
|
764
|
+
const i = this._reactivity;
|
|
765
|
+
let a = !1;
|
|
766
|
+
for (let r = y; r < t.length; r++) {
|
|
767
|
+
const d = t[r];
|
|
768
|
+
d === null || d.firstDep !== null || !i._beginTaskEffectRun(d) || (s ? i._disposeTaskEffect(d) : (i._requestTaskEffect(d, !1), a = !0));
|
|
769
|
+
}
|
|
770
|
+
if (a)
|
|
771
|
+
return !1;
|
|
772
|
+
const n = !s && F(e);
|
|
773
|
+
let o = !1;
|
|
774
|
+
for (let r = y; r < t.length; r++) {
|
|
775
|
+
const d = t[r];
|
|
776
|
+
if (d === null)
|
|
777
|
+
continue;
|
|
778
|
+
if (d.firstDep === null) {
|
|
779
|
+
o = o || d.evaluate !== void 0;
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
const l = n && i._beginTaskEffectRun(d);
|
|
783
|
+
i._cancelTaskEffect(d) && (o = !0, l && i._rearmTaskEffect(d));
|
|
784
|
+
}
|
|
785
|
+
return o;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Сбрасывает ожидающую работу записи, снятой с очереди либо из отложенных.
|
|
789
|
+
* Такая запись не находится в доставке, поэтому её причины ожидающие.
|
|
790
|
+
*/
|
|
791
|
+
_clearPendingDelivery(e) {
|
|
792
|
+
e.state &= ~g, e.firstCause = void 0, e.firstCauseKey = void 0;
|
|
793
|
+
const t = e.detail;
|
|
794
|
+
t !== void 0 && (t.extraCauses?.clear(), t.extraCauses = void 0);
|
|
795
|
+
}
|
|
796
|
+
_settleIdleWaiters(e, t) {
|
|
797
|
+
const s = this._idleWaiters;
|
|
798
|
+
if (s.size === 0 || !t && (this._running || this._scheduled || this._hasPending()))
|
|
799
|
+
return;
|
|
800
|
+
const i = [...s];
|
|
801
|
+
s.clear();
|
|
802
|
+
for (const a of i)
|
|
803
|
+
t ? a.reject(e) : a.resolve();
|
|
804
|
+
}
|
|
805
|
+
_assertAlive() {
|
|
806
|
+
if (this._disposed)
|
|
807
|
+
throw new I("[Raph] Phase pipeline is disposed.");
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function Y(h, e) {
|
|
811
|
+
return e.priority - h.priority || h.sequence - e.sequence;
|
|
812
|
+
}
|
|
813
|
+
function F(h) {
|
|
814
|
+
return h.firstCause !== void 0 && !(h.state & k);
|
|
815
|
+
}
|
|
816
|
+
function S(h) {
|
|
817
|
+
const e = h.state, t = h.detail;
|
|
818
|
+
if (e & k) {
|
|
819
|
+
h.state = e & ~k, h.firstCause = void 0, h.firstCauseKey = void 0, t !== void 0 && (t.extraCauses = void 0, t.deliveryCauses = void 0);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
t !== void 0 && t.deliveryFirstCause !== void 0 && L(t);
|
|
823
|
+
}
|
|
824
|
+
function L(h) {
|
|
825
|
+
h.deliveryFirstCause = void 0, h.deliveryFirstCauseKey = void 0, h.deliveryExtraCauses = void 0, h.deliveryCauses = void 0;
|
|
826
|
+
}
|
|
827
|
+
function O() {
|
|
828
|
+
throw new R("[Raph] Phase task delivery is already resolved.");
|
|
829
|
+
}
|
|
830
|
+
function U(h, e) {
|
|
831
|
+
const t = h.events === void 0 ? e.events : e.events === void 0 ? h.events : Object.freeze([...h.events, ...e.events]), s = h.structure === void 0 ? e.structure : e.structure === void 0 ? h.structure : Object.freeze({
|
|
832
|
+
node: e.structure.node,
|
|
833
|
+
oldParent: h.structure.oldParent,
|
|
834
|
+
oldIndex: h.structure.oldIndex,
|
|
835
|
+
newParent: e.structure.newParent,
|
|
836
|
+
newIndex: e.structure.newIndex
|
|
837
|
+
});
|
|
838
|
+
return Object.freeze({
|
|
839
|
+
...e,
|
|
840
|
+
previous: h.previous,
|
|
841
|
+
...t === void 0 ? {} : { events: t },
|
|
842
|
+
...s === void 0 ? {} : { structure: s }
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
export {
|
|
846
|
+
te as RaphPhasePipeline,
|
|
847
|
+
Q as RaphPhaseState
|
|
848
|
+
};
|