@raphy-js/raph 1.0.1-dev.25 → 1.0.1-dev.54
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 +100 -0
- package/dist/api/Raph.d.ts +15 -15
- package/dist/api/RaphFacadeSession.d.ts +4 -4
- package/dist/api/RaphReactivityInstance.d.ts +4 -4
- package/dist/api/types.d.ts +11 -11
- package/dist/compact.cjs +1 -0
- package/dist/compact.js +4 -0
- package/dist/debug/reactivity/engine-core.cjs +1 -0
- package/dist/debug/reactivity/engine-core.js +1760 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +25 -1689
- package/dist/debug/reactivity/reactive-object.cjs +1 -1
- package/dist/debug/reactivity/reactive-object.js +604 -167
- package/dist/debug/runtime/RaphCompactExecutionRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphCompactExecutionRuntime.js +9 -0
- package/dist/debug/runtime/RaphExecutionRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphExecutionRuntime.js +11 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +115 -1176
- package/dist/debug/runtime/RaphRuntimeBase.cjs +1 -0
- package/dist/debug/runtime/RaphRuntimeBase.js +941 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
- package/dist/debug/runtime/diagnostics/RaphDebug.js +72 -66
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphNode.js +11 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphScope.js +12 -12
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +361 -242
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +23 -22
- package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -1
- package/dist/debug/runtime/reactivity/RaphSelector.js +111 -90
- package/dist/debug/runtime/reactivity/RuntimeObjectSupport.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeObjectSupport.js +11 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +118 -103
- package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.js +12 -0
- package/dist/entrypoints/compact.d.ts +2 -0
- package/dist/entrypoints/execution.d.ts +2 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -2
- package/dist/entrypoints/machine.d.ts +5 -5
- package/dist/entrypoints/observable.d.ts +4 -0
- package/dist/entrypoints/path.d.ts +14 -14
- package/dist/entrypoints/reactivity.d.ts +1 -1
- package/dist/entrypoints/runtime.d.ts +19 -18
- package/dist/execution.cjs +1 -0
- package/dist/execution.js +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +23 -21
- package/dist/machine/compiler.d.ts +1 -1
- package/dist/machine/core.d.ts +2 -2
- package/dist/machine/persistence.d.ts +1 -1
- package/dist/machine/runtime.d.ts +3 -3
- package/dist/machine/testing.d.ts +1 -1
- package/dist/machine/types.d.ts +3 -3
- package/dist/main.d.ts +19 -19
- package/dist/observable/buffer.d.ts +6 -0
- package/dist/observable/class-admin.d.ts +63 -0
- package/dist/observable/class-plan.d.ts +46 -0
- package/dist/observable/classes.d.ts +10 -0
- package/dist/observable/context.d.ts +73 -0
- package/dist/observable/native.d.ts +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/types.d.ts +60 -0
- package/dist/observable.cjs +1 -0
- package/dist/observable.js +1187 -0
- package/dist/path/DataPath.d.ts +2 -2
- package/dist/path/PathRouter.d.ts +1 -1
- package/dist/path/RaphKernel.d.ts +6 -6
- package/dist/path/data-path.types.d.ts +1 -1
- package/dist/path/data-path.utils.d.ts +2 -2
- package/dist/path/derived/DerivedRegistry.d.ts +3 -3
- package/dist/path/derived/RaphDerivedHandle.d.ts +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +1 -1
- package/dist/path/derived/derived-collection.utils.d.ts +3 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +1 -1
- package/dist/path/meta/MetaController.d.ts +5 -5
- package/dist/path/meta/RaphMeta.d.ts +3 -3
- package/dist/path/meta/RaphMetaStore.d.ts +1 -1
- package/dist/path/meta/meta.types.d.ts +2 -2
- package/dist/path/path.types.d.ts +2 -2
- package/dist/path/pathSegmentKey.d.ts +1 -1
- package/dist/path/storage/AdapterPathStore.d.ts +2 -2
- package/dist/path/storage/DefaultDataAdapter.d.ts +2 -2
- package/dist/path/storage/PathEventHub.d.ts +1 -1
- package/dist/path/storage/PathStore.d.ts +2 -2
- package/dist/path/storage/data-adapter.types.d.ts +1 -1
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +23 -21
- package/dist/reactivity/engine-core.d.ts +600 -0
- package/dist/reactivity/engine.d.ts +6 -550
- package/dist/reactivity/reactive-object.d.ts +143 -2
- package/dist/reactivity/scope.d.ts +7 -6
- package/dist/reactivity/types.d.ts +9 -12
- package/dist/reactivity/watch.d.ts +1 -1
- package/dist/runtime/RaphCompactExecutionRuntime.d.ts +7 -0
- package/dist/runtime/RaphExecutionRuntime.d.ts +6 -0
- package/dist/runtime/RaphRuntime.d.ts +19 -403
- package/dist/runtime/RaphRuntimeBase.d.ts +194 -0
- package/dist/runtime/diagnostics/RaphDebug.d.ts +8 -5
- package/dist/runtime/errors.d.ts +1 -1
- package/dist/runtime/ownership/RaphEffectScope.d.ts +13 -12
- package/dist/runtime/ownership/RaphNode.d.ts +28 -21
- package/dist/runtime/ownership/RaphScope.d.ts +32 -19
- package/dist/runtime/ownership/parent-graph.types.d.ts +1 -1
- package/dist/runtime/ownership/parentGraph.d.ts +2 -2
- package/dist/runtime/phases/RaphFrameLoop.d.ts +1 -1
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +80 -29
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +21 -21
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +3 -3
- package/dist/runtime/phases/orderPhaseTasks.d.ts +4 -2
- package/dist/runtime/phases/phase.types.d.ts +36 -35
- package/dist/runtime/reactivity/PathHandle.d.ts +5 -5
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +7 -7
- package/dist/runtime/reactivity/RaphSelector.d.ts +27 -6
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +40 -39
- package/dist/runtime/reactivity/RuntimeObjectSupport.d.ts +9 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +27 -19
- package/dist/runtime/reactivity/RuntimeSelectorSupport.d.ts +10 -0
- package/dist/runtime/reactivity/RuntimeWatch.d.ts +1 -1
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +1 -1
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +3 -3
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +13 -11
- package/package.json +22 -62
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=Object.freeze([]),d=Object.freeze({now:0,delta:0,elapsed:0,frame:0}),o=1,E=2,p=4,T=8,u=16,l=32,A=64,f=128,S=256,R=1536,D=0,v=512,K=1024,C=1536,O=2048,h=4096,P=0,U=1,m=2;class _{constructor(e){this._record=e,Object.freeze(this)}get phase(){return this._record.phaseState.name}get consumerOwner(){return this._record.consumerOwner}get effect(){return this._record.effect}get causes(){return this._record.causes}get frame(){const e=this._record;return e.state&h||(e.frame=e.phaseState.pipeline._exposeFrame(e.frame),e.state|=h),e.frame}get priority(){return this._record.priority}get sequence(){return this._record.sequence}run(){const e=this._record;e.phaseState.pipeline._runDelivery(e)}defer(){const e=this._record;e.phaseState.pipeline._deferDelivery(e)}cancel(){const e=this._record;e.phaseState.pipeline._cancelDelivery(e)}}class a{constructor(){this.extraCauses=void 0,this.deliveryFirstCause=void 0,this.deliveryFirstCauseKey=void 0,this.deliveryExtraCauses=void 0,this.deliveryCauses=void 0,this.deferCount=0}}a._shapeAnchor=new a;class y{constructor(e,t,s,i){this.state=o,this.sequence=0,this.phaseState=e,this.priority=t,this.consumerOwner=s,this.effect=i,this.node=void 0,this.watch=void 0,this.group=void 0,this.scopeParent=void 0,this.scopePrevious=void 0,this.scopeNext=void 0,this.firstCause=void 0,this.firstCauseKey=void 0,this.frame=d,this.facade=void 0,this.detail=void 0}get phase(){return this.phaseState.name}get dependencyOwner(){return this.consumerOwner}get allowScheduleDuringRun(){return!0}get active(){return(this.state&o)!==0}get causes(){const e=this.detail;if(e!==void 0){const r=e.deliveryCauses;if(r!==void 0)return r}let t,s;if(this.state&S?(t=this.firstCause,e!==void 0&&(s=e.extraCauses)):e!==void 0&&(t=e.deliveryFirstCause,s=e.deliveryExtraCauses),t===void 0)return c;const i=[Object.freeze(t)];if(s!==void 0)for(const r of s.values())i.push(Object.freeze(r));return this.detailed().deliveryCauses=Object.freeze(i)}get task(){let e=this.facade;return e===void 0&&(this.state&u&&(this.frame=this.phaseState.pipeline._frameForDelivery()),this.facade=e=new _(this)),e}detailed(){return this.detail??=new a}notify(e){this.phaseState.pipeline._notifyTask(this,e)}schedule(){this.phaseState.pipeline._queue(this,!0)}enqueue(e,t=e.source,s=!0){const i=this.phaseState.pipeline;i._appendCause(this,e,t),i._queue(this,s)}start(e,t="scheduled"){this.consumerOwner.runtime._startGroupSlot(this,e,t)}_start(e,t,s){this.consumerOwner.runtime._startGroupSlot(this,e,t,s)}pause(){this.phaseState.pipeline._pauseTask(this)}resume(){this.phaseState.pipeline._resumeTask(this)}dispose(){this.phaseState.pipeline._disposeBinding(this)}}exports.EMPTY_CAUSES=c;exports.EMPTY_FRAME=d;exports.GROUP_CONTEXT=P;exports.GROUP_CURSOR=U;exports.GROUP_NODES=m;exports.RaphPhaseTaskDetail=a;exports.RaphPhaseTaskHandle=_;exports.RaphPhaseTaskRecord=y;exports.TASK_ACTIVE=o;exports.TASK_CANCEL=C;exports.TASK_CAUSES_DELIVERED=S;exports.TASK_DEFER=K;exports.TASK_DEFERRED=T;exports.TASK_DISCARD_ACKNOWLEDGED=l;exports.TASK_EXECUTED=f;exports.TASK_IN_DELIVERY=u;exports.TASK_PAUSED=E;exports.TASK_PENDING=p;exports.TASK_REQUESTED=A;exports.TASK_RESOLUTION=R;exports.TASK_RUN=v;exports.TASK_TASKLESS=O;exports.TASK_UNRESOLVED=D;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const h = Object.freeze([]),
|
|
2
|
-
class
|
|
1
|
+
const h = Object.freeze([]), d = Object.freeze({ now: 0, delta: 0, elapsed: 0, frame: 0 }), n = 1, l = 2, S = 4, f = 8, u = 16, E = 32, v = 64, T = 128, p = 256, A = 1536, C = 0, O = 512, D = 1024, R = 1536, m = 2048, c = 4096, y = 0, K = 1, g = 2;
|
|
2
|
+
class _ {
|
|
3
3
|
constructor(e) {
|
|
4
4
|
this._record = e, Object.freeze(this);
|
|
5
5
|
}
|
|
@@ -16,7 +16,8 @@ class p {
|
|
|
16
16
|
return this._record.causes;
|
|
17
17
|
}
|
|
18
18
|
get frame() {
|
|
19
|
-
|
|
19
|
+
const e = this._record;
|
|
20
|
+
return e.state & c || (e.frame = e.phaseState.pipeline._exposeFrame(e.frame), e.state |= c), e.frame;
|
|
20
21
|
}
|
|
21
22
|
get priority() {
|
|
22
23
|
return this._record.priority;
|
|
@@ -43,9 +44,9 @@ class a {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
a._shapeAnchor = new a();
|
|
46
|
-
class
|
|
47
|
+
class w {
|
|
47
48
|
constructor(e, t, s, i) {
|
|
48
|
-
this.state = n, this.sequence = 0, this.phaseState = e, this.priority = t, this.consumerOwner = s, this.effect = i, this.node = void 0, this.watch = void 0, this.group = void 0, this.scopeParent = void 0, this.scopePrevious = void 0, this.scopeNext = void 0, this.firstCause = void 0, this.firstCauseKey = void 0, this.frame =
|
|
49
|
+
this.state = n, this.sequence = 0, this.phaseState = e, this.priority = t, this.consumerOwner = s, this.effect = i, this.node = void 0, this.watch = void 0, this.group = void 0, this.scopeParent = void 0, this.scopePrevious = void 0, this.scopeNext = void 0, this.firstCause = void 0, this.firstCauseKey = void 0, this.frame = d, this.facade = void 0, this.detail = void 0;
|
|
49
50
|
}
|
|
50
51
|
get phase() {
|
|
51
52
|
return this.phaseState.name;
|
|
@@ -82,7 +83,7 @@ class g {
|
|
|
82
83
|
return r;
|
|
83
84
|
}
|
|
84
85
|
let t, s;
|
|
85
|
-
if (this.state &
|
|
86
|
+
if (this.state & p ? (t = this.firstCause, e !== void 0 && (s = e.extraCauses)) : e !== void 0 && (t = e.deliveryFirstCause, s = e.deliveryExtraCauses), t === void 0)
|
|
86
87
|
return h;
|
|
87
88
|
const i = [Object.freeze(t)];
|
|
88
89
|
if (s !== void 0)
|
|
@@ -100,7 +101,7 @@ class g {
|
|
|
100
101
|
*/
|
|
101
102
|
get task() {
|
|
102
103
|
let e = this.facade;
|
|
103
|
-
return e === void 0 && (this.state & u && (this.frame = this.phaseState.pipeline.
|
|
104
|
+
return e === void 0 && (this.state & u && (this.frame = this.phaseState.pipeline._frameForDelivery()), this.facade = e = new _(this)), e;
|
|
104
105
|
}
|
|
105
106
|
/** Возвращает редкое состояние записи и создаёт его при первом обращении. */
|
|
106
107
|
detailed() {
|
|
@@ -151,26 +152,26 @@ class g {
|
|
|
151
152
|
}
|
|
152
153
|
export {
|
|
153
154
|
h as EMPTY_CAUSES,
|
|
154
|
-
|
|
155
|
+
d as EMPTY_FRAME,
|
|
155
156
|
y as GROUP_CONTEXT,
|
|
156
157
|
K as GROUP_CURSOR,
|
|
157
|
-
|
|
158
|
+
g as GROUP_NODES,
|
|
158
159
|
a as RaphPhaseTaskDetail,
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
_ as RaphPhaseTaskHandle,
|
|
161
|
+
w as RaphPhaseTaskRecord,
|
|
161
162
|
n as TASK_ACTIVE,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
R as TASK_CANCEL,
|
|
164
|
+
p as TASK_CAUSES_DELIVERED,
|
|
165
|
+
D as TASK_DEFER,
|
|
166
|
+
f as TASK_DEFERRED,
|
|
167
|
+
E as TASK_DISCARD_ACKNOWLEDGED,
|
|
168
|
+
T as TASK_EXECUTED,
|
|
168
169
|
u as TASK_IN_DELIVERY,
|
|
169
170
|
l as TASK_PAUSED,
|
|
170
|
-
|
|
171
|
+
S as TASK_PENDING,
|
|
171
172
|
v as TASK_REQUESTED,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
A as TASK_RESOLUTION,
|
|
174
|
+
O as TASK_RUN,
|
|
175
|
+
m as TASK_TASKLESS,
|
|
176
|
+
C as TASK_UNRESOLVED
|
|
176
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=32,g=32;class f{constructor(e,s,t,i){this.select=l(this),this._previousSource=void 0,this._trackedKey=void 0,this._owner=e,this._reactivity=s,this._source=t,this._equals=i,this._dense=[],this._denseBase=0,this._denseCount=0,this._triggers=void 0,this._scanning=!1,this._objectHooks=p(this,t),this._growthLimit=1,this._sweptAt=0,this._sweepStride=0,this._disposed=!1,this._tapSlot=-1,this._sweepSlot=-1,this._sweepDue=0,t._addWriteTap(this)}get[Symbol.toStringTag](){return"RaphSelector"}toJSON(){return{owner:this._owner.id,triggers:this._size(),disposed:this._disposed}}get _tapOwner(){return this._owner}_debugTriggerCount(){return this._size()}_test(e){const s=this._owner,t=this._reactivity;t._assertTrackedRead(s),s._assertAlive(),this._track(e,t);const i=this._source.peek(),r=this._equals;return r!==void 0?r(e,i):e===i||typeof e=="number"&&typeof i=="number"&&Object.is(e,i)}_observesWrites(){return this._size()!==0}_inspect(){if(this._equals!==void 0)return;const e=this._owner,s=this._source;return{read:()=>s.get(),test:t=>{e._assertAlive();const i=s.peek();return t===i||typeof t=="number"&&typeof i=="number"&&Object.is(t,i)}}}_afterSourceWrite(e,s){if(this._size()===0)return;const t=this._reactivity,i=this._equals;if(i===void 0){if(Object.is(e,s))return;this._wakePair(e,s,t);return}let r;const n=this._scanning;this._scanning=!0;const o=this._dense;for(let _=0;_<o.length;_++){const d=o[_];if(d!==void 0){if(!t._signalNodeHasSubscribers(d)){o[_]=void 0,this._denseCount--;continue}r=this._wakeChanged(this._denseBase+_,d,e,s,i,r)}}const h=this._triggers;if(h!==void 0)for(const[_,d]of h){if(!t._signalNodeHasSubscribers(d)){h.delete(_);continue}r=this._wakeChanged(_,d,e,s,i,r)}if(this._scanning=n,this._settleDense(),r!==void 0)throw r.length===1?r[0]:new AggregateError(r,"[Raph] Selector notification failed.")}_afterOwnerDisposals(e){const s=this._size(),t=this._sweepStride,i=this._sweptAt+(t>s?t:s);if(e<i)return i;this._sweep(e);const r=this._size();if(r===0)return this._sweepStride=0,this._growthLimit=1,0;if(r!==s)return this._sweepStride=0,e+r;const n=(t>r?t:r)*2;return this._sweepStride=n,e+n}_edgeDetached(e){if(this._disposed)return;const s=this._triggers,t=s.get(e);t!==void 0&&this._reactivity._hasSingleSubscriber(t)&&s.delete(e)}_findConsumerOwner(e,s){const t=this._reactivity,i=this._dense;for(let n=0;n<i.length;n++){const o=i[n];if(o===void 0)continue;const h=t._findSubscriberOwner(o,e,s);if(h!==void 0)return h}const r=this._triggers;if(r!==void 0)for(const n of r.values()){const o=t._findSubscriberOwner(n,e,s);if(o!==void 0)return o}}_finalizeSource(){if(this._disposed)return!0;this._disposed=!0,this._equals=void 0,this._source._removeWriteTap(this),this._sweepSlot!==-1&&this._owner.runtime._removeDisposalSweeper(this);const e=this._reactivity;let s;const t=this._dense;for(let r=0;r<t.length;r++){const n=t[r];if(n!==void 0)try{e._releaseSignalNode(n)}catch(o){(s??=[]).push(o)}}t.length=0,this._denseCount=0;const i=this._triggers;if(i!==void 0){for(const r of i.values())try{e._releaseSignalNode(r)}catch(n){(s??=[]).push(n)}i.clear()}if(s!==void 0)throw s.length===1?s[0]:new AggregateError(s,"[Raph] Selector disposal failed.");return!0}_sweep(e=this._owner.runtime._ownerDisposalCount()){this._sweptAt=e;const s=this._size();if(s===0)return;const t=this._dense,i=this._triggers,r=this._reactivity,n=r._countObserved(t,i);if(n===s){t.length!==this._denseCount&&this._settleDense();return}if(n===0){t.length=0,this._denseCount=0,i!==void 0&&i.clear();return}this._denseCount=r._dropUnobserved(t,i),this._settleDense()}_size(){const e=this._triggers;return e===void 0?this._denseCount:this._denseCount+e.size}_track(e,s){if(typeof e=="number"){const n=this._dense,o=n.length;if(o===0){if(Number.isInteger(e)){this._trackDense(e,0,s);return}}else{const h=this._denseBase,_=e-h;if(_>=0&&_<=o&&_===(_|0)&&h+_===e){const d=_<o?n[_]:void 0;d!==void 0?s._readSignalNode(d):this._trackDense(e,_,s);return}}}const t=this._triggers,i=t===void 0?void 0:t.get(e);if(typeof e=="object"?e!==null:typeof e=="function"){this._trackObject(e,i,s);return}if(i!==void 0){s._readSignalNode(i);return}const r=s._trackCounterNode(this._source);r!==void 0&&(t===void 0?this._triggers=new Map().set(e,r):t.set(e,r),this._size()>=this._growthLimit&&this._grow())}_trackDense(e,s,t){const i=this._triggers;if(i!==void 0&&i.size!==0){const o=i.get(e);if(o!==void 0){t._readSignalNode(o);return}}const r=t._trackCounterNode(this._source);if(r===void 0)return;const n=this._dense;s===n.length?(s===0&&(this._denseBase=e+0),n.push(r)):n[s]=r,this._denseCount++,this._size()>=this._growthLimit&&this._grow()}_trackObject(e,s,t){if(this._trackedKey=e,s!==void 0)t._readSignalNode(s);else{const i=t._trackCounterNode(this._objectHooks);if(i!==void 0){const r=this._triggers;r===void 0?this._triggers=new Map().set(e,i):r.set(e,i),this._size()>=this._growthLimit&&this._grow()}}this._trackedKey=void 0}_grow(){const e=this._owner.runtime,s=e._ownerDisposalCount();this._sweep(s);const t=this._size();this._growthLimit=t*2>u?t*2:u,this._sweepSlot===-1&&(this._sweepStride=0,e._addDisposalSweeper(this,s+t))}_wakePair(e,s,t){let i=!1,r;const n=this._find(e);if(n!==void 0)try{this._bump(e,n,t)}catch(h){i=!0,r=h}const o=this._find(s);if(o!==void 0)try{this._bump(s,o,t)}catch(h){throw i?new AggregateError([r,h],"[Raph] Selector notification failed."):h}if(i)throw r}_bump(e,s,t){t._bumpSignalNode(s)||this._forget(e)}_wakeChanged(e,s,t,i,r,n){let o=!0;try{o=r(e,t)!==r(e,i)}catch(h){(n??=[]).push(h)}if(o)try{this._bump(e,s,this._reactivity)}catch(h){(n??=[]).push(h)}return n}_find(e){if(typeof e=="number"){const t=this._dense,i=this._denseBase,r=e-i;if(r>=0&&r<t.length&&r===(r|0)&&i+r===e)return t[r]}const s=this._triggers;return s===void 0?void 0:s.get(e)}_forget(e){if(typeof e=="number"){const t=this._dense,i=this._denseBase,r=e-i;if(r>=0&&r<t.length&&r===(r|0)&&i+r===e){if(t[r]!==void 0){t[r]=void 0;const n=--this._denseCount;(n===0||t.length>(n*2+g)*2)&&this._settleDense()}return}}const s=this._triggers;s!==void 0&&s.delete(e)}_settleDense(){if(this._scanning)return;const e=this._dense,s=this._denseCount;if(s===0){e.length=0;return}let t=e.length,i=0;for(;i<t&&e[i]===void 0;)i++;for(;t>i&&e[t-1]===void 0;)t--;if(t-i>s*2+g){const r=this._denseBase,n=this._triggers??=new Map;for(let o=i;o<t;o++){const h=e[o];h!==void 0&&n.set(r+o,h)}e.length=0,this._denseCount=0;return}i!==0&&(e.copyWithin(0,i,t),this._denseBase+=i),e.length=t-i}}function l(c){const e=s=>c._test(s);return a.set(e,c),e}const a=new WeakMap;function w(c){if(typeof c=="function")return a.get(c)?._inspect()}function p(c,e){return{token:e,onDependency:()=>{const s=c._trackedKey;return()=>{c._edgeDetached(s)}}}}exports.RuntimeSelector=f;exports.inspectSelector=w;
|
|
@@ -3,8 +3,8 @@ class f {
|
|
|
3
3
|
* Создаёт selector и подключает его к записям source. Регистрацию у
|
|
4
4
|
* владельца и проверку аргументов выполняет вызывающий код.
|
|
5
5
|
*/
|
|
6
|
-
constructor(e, s, t,
|
|
7
|
-
this.select =
|
|
6
|
+
constructor(e, s, t, i) {
|
|
7
|
+
this.select = u(this), this._previousSource = void 0, this._trackedKey = void 0, this._owner = e, this._reactivity = s, this._source = t, this._equals = i, this._dense = [], this._denseBase = 0, this._denseCount = 0, this._triggers = void 0, this._scanning = !1, this._objectHooks = a(this, t), this._growthLimit = 1, this._sweptAt = 0, this._sweepStride = 0, this._disposed = !1, this._tapSlot = -1, this._sweepSlot = -1, this._sweepDue = 0, t._addWriteTap(this);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Тег Object.prototype.toString: инструменты, которые обходят только plain
|
|
@@ -52,8 +52,8 @@ class f {
|
|
|
52
52
|
_test(e) {
|
|
53
53
|
const s = this._owner, t = this._reactivity;
|
|
54
54
|
t._assertTrackedRead(s), s._assertAlive(), this._track(e, t);
|
|
55
|
-
const
|
|
56
|
-
return
|
|
55
|
+
const i = this._source.peek(), r = this._equals;
|
|
56
|
+
return r !== void 0 ? r(e, i) : e === i || typeof e == "number" && typeof i == "number" && Object.is(e, i);
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* Сообщает, что запись в source может разбудить потребителей selector.
|
|
@@ -62,6 +62,20 @@ class f {
|
|
|
62
62
|
_observesWrites() {
|
|
63
63
|
return this._size() !== 0;
|
|
64
64
|
}
|
|
65
|
+
/** @internal См. `inspectSelector`. */
|
|
66
|
+
_inspect() {
|
|
67
|
+
if (this._equals !== void 0)
|
|
68
|
+
return;
|
|
69
|
+
const e = this._owner, s = this._source;
|
|
70
|
+
return {
|
|
71
|
+
read: () => s.get(),
|
|
72
|
+
test: (t) => {
|
|
73
|
+
e._assertAlive();
|
|
74
|
+
const i = s.peek();
|
|
75
|
+
return t === i || typeof t == "number" && typeof i == "number" && Object.is(t, i);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
65
79
|
/**
|
|
66
80
|
* Будит потребителей ключей, чей ответ изменила запись в source. Вызывается
|
|
67
81
|
* signal-ом после того, как новое значение стало видимым, внутри его границы
|
|
@@ -71,45 +85,45 @@ class f {
|
|
|
71
85
|
_afterSourceWrite(e, s) {
|
|
72
86
|
if (this._size() === 0)
|
|
73
87
|
return;
|
|
74
|
-
const t = this._reactivity,
|
|
75
|
-
if (
|
|
88
|
+
const t = this._reactivity, i = this._equals;
|
|
89
|
+
if (i === void 0) {
|
|
76
90
|
if (Object.is(e, s))
|
|
77
91
|
return;
|
|
78
92
|
this._wakePair(e, s, t);
|
|
79
93
|
return;
|
|
80
94
|
}
|
|
81
|
-
let
|
|
95
|
+
let r;
|
|
82
96
|
const n = this._scanning;
|
|
83
97
|
this._scanning = !0;
|
|
84
98
|
const o = this._dense;
|
|
85
99
|
for (let _ = 0; _ < o.length; _++) {
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
if (!t._signalNodeHasSubscribers(
|
|
100
|
+
const c = o[_];
|
|
101
|
+
if (c !== void 0) {
|
|
102
|
+
if (!t._signalNodeHasSubscribers(c)) {
|
|
89
103
|
o[_] = void 0, this._denseCount--;
|
|
90
104
|
continue;
|
|
91
105
|
}
|
|
92
|
-
|
|
106
|
+
r = this._wakeChanged(
|
|
93
107
|
this._denseBase + _,
|
|
94
|
-
|
|
108
|
+
c,
|
|
95
109
|
e,
|
|
96
110
|
s,
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
i,
|
|
112
|
+
r
|
|
99
113
|
);
|
|
100
114
|
}
|
|
101
115
|
}
|
|
102
116
|
const h = this._triggers;
|
|
103
117
|
if (h !== void 0)
|
|
104
|
-
for (const [_,
|
|
105
|
-
if (!t._signalNodeHasSubscribers(
|
|
118
|
+
for (const [_, c] of h) {
|
|
119
|
+
if (!t._signalNodeHasSubscribers(c)) {
|
|
106
120
|
h.delete(_);
|
|
107
121
|
continue;
|
|
108
122
|
}
|
|
109
|
-
|
|
123
|
+
r = this._wakeChanged(_, c, e, s, i, r);
|
|
110
124
|
}
|
|
111
|
-
if (this._scanning = n, this._settleDense(),
|
|
112
|
-
throw
|
|
125
|
+
if (this._scanning = n, this._settleDense(), r !== void 0)
|
|
126
|
+
throw r.length === 1 ? r[0] : new AggregateError(r, "[Raph] Selector notification failed.");
|
|
113
127
|
}
|
|
114
128
|
/**
|
|
115
129
|
* Убирает triggers без потребителей, когда Runtime после прошлой уборки
|
|
@@ -125,16 +139,16 @@ class f {
|
|
|
125
139
|
* @internal
|
|
126
140
|
*/
|
|
127
141
|
_afterOwnerDisposals(e) {
|
|
128
|
-
const s = this._size(), t = this._sweepStride,
|
|
129
|
-
if (e <
|
|
130
|
-
return
|
|
142
|
+
const s = this._size(), t = this._sweepStride, i = this._sweptAt + (t > s ? t : s);
|
|
143
|
+
if (e < i)
|
|
144
|
+
return i;
|
|
131
145
|
this._sweep(e);
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
146
|
+
const r = this._size();
|
|
147
|
+
if (r === 0)
|
|
134
148
|
return this._sweepStride = 0, this._growthLimit = 1, 0;
|
|
135
|
-
if (
|
|
136
|
-
return this._sweepStride = 0, e +
|
|
137
|
-
const n = (t >
|
|
149
|
+
if (r !== s)
|
|
150
|
+
return this._sweepStride = 0, e + r;
|
|
151
|
+
const n = (t > r ? t : r) * 2;
|
|
138
152
|
return this._sweepStride = n, e + n;
|
|
139
153
|
}
|
|
140
154
|
/**
|
|
@@ -159,18 +173,18 @@ class f {
|
|
|
159
173
|
* @internal
|
|
160
174
|
*/
|
|
161
175
|
_findConsumerOwner(e, s) {
|
|
162
|
-
const t = this._reactivity,
|
|
163
|
-
for (let n = 0; n <
|
|
164
|
-
const o =
|
|
176
|
+
const t = this._reactivity, i = this._dense;
|
|
177
|
+
for (let n = 0; n < i.length; n++) {
|
|
178
|
+
const o = i[n];
|
|
165
179
|
if (o === void 0)
|
|
166
180
|
continue;
|
|
167
181
|
const h = t._findSubscriberOwner(o, e, s);
|
|
168
182
|
if (h !== void 0)
|
|
169
183
|
return h;
|
|
170
184
|
}
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
for (const n of
|
|
185
|
+
const r = this._triggers;
|
|
186
|
+
if (r !== void 0)
|
|
187
|
+
for (const n of r.values()) {
|
|
174
188
|
const o = t._findSubscriberOwner(n, e, s);
|
|
175
189
|
if (o !== void 0)
|
|
176
190
|
return o;
|
|
@@ -190,8 +204,8 @@ class f {
|
|
|
190
204
|
const e = this._reactivity;
|
|
191
205
|
let s;
|
|
192
206
|
const t = this._dense;
|
|
193
|
-
for (let
|
|
194
|
-
const n = t[
|
|
207
|
+
for (let r = 0; r < t.length; r++) {
|
|
208
|
+
const n = t[r];
|
|
195
209
|
if (n !== void 0)
|
|
196
210
|
try {
|
|
197
211
|
e._releaseSignalNode(n);
|
|
@@ -200,15 +214,15 @@ class f {
|
|
|
200
214
|
}
|
|
201
215
|
}
|
|
202
216
|
t.length = 0, this._denseCount = 0;
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
for (const
|
|
217
|
+
const i = this._triggers;
|
|
218
|
+
if (i !== void 0) {
|
|
219
|
+
for (const r of i.values())
|
|
206
220
|
try {
|
|
207
|
-
e._releaseSignalNode(
|
|
221
|
+
e._releaseSignalNode(r);
|
|
208
222
|
} catch (n) {
|
|
209
223
|
(s ??= []).push(n);
|
|
210
224
|
}
|
|
211
|
-
|
|
225
|
+
i.clear();
|
|
212
226
|
}
|
|
213
227
|
if (s !== void 0)
|
|
214
228
|
throw s.length === 1 ? s[0] : new AggregateError(s, "[Raph] Selector disposal failed.");
|
|
@@ -225,16 +239,16 @@ class f {
|
|
|
225
239
|
const s = this._size();
|
|
226
240
|
if (s === 0)
|
|
227
241
|
return;
|
|
228
|
-
const t = this._dense,
|
|
242
|
+
const t = this._dense, i = this._triggers, r = this._reactivity, n = r._countObserved(t, i);
|
|
229
243
|
if (n === s) {
|
|
230
244
|
t.length !== this._denseCount && this._settleDense();
|
|
231
245
|
return;
|
|
232
246
|
}
|
|
233
247
|
if (n === 0) {
|
|
234
|
-
t.length = 0, this._denseCount = 0,
|
|
248
|
+
t.length = 0, this._denseCount = 0, i !== void 0 && i.clear();
|
|
235
249
|
return;
|
|
236
250
|
}
|
|
237
|
-
this._denseCount =
|
|
251
|
+
this._denseCount = r._dropUnobserved(t, i), this._settleDense();
|
|
238
252
|
}
|
|
239
253
|
/**
|
|
240
254
|
* Число ключей в обеих частях индекса: с потребителями и ещё не убранных.
|
|
@@ -258,23 +272,23 @@ class f {
|
|
|
258
272
|
} else {
|
|
259
273
|
const h = this._denseBase, _ = e - h;
|
|
260
274
|
if (_ >= 0 && _ <= o && _ === (_ | 0) && h + _ === e) {
|
|
261
|
-
const
|
|
262
|
-
|
|
275
|
+
const c = _ < o ? n[_] : void 0;
|
|
276
|
+
c !== void 0 ? s._readSignalNode(c) : this._trackDense(e, _, s);
|
|
263
277
|
return;
|
|
264
278
|
}
|
|
265
279
|
}
|
|
266
280
|
}
|
|
267
|
-
const t = this._triggers,
|
|
281
|
+
const t = this._triggers, i = t === void 0 ? void 0 : t.get(e);
|
|
268
282
|
if (typeof e == "object" ? e !== null : typeof e == "function") {
|
|
269
|
-
this._trackObject(e,
|
|
283
|
+
this._trackObject(e, i, s);
|
|
270
284
|
return;
|
|
271
285
|
}
|
|
272
|
-
if (
|
|
273
|
-
s._readSignalNode(
|
|
286
|
+
if (i !== void 0) {
|
|
287
|
+
s._readSignalNode(i);
|
|
274
288
|
return;
|
|
275
289
|
}
|
|
276
|
-
const
|
|
277
|
-
|
|
290
|
+
const r = s._trackCounterNode(this._source);
|
|
291
|
+
r !== void 0 && (t === void 0 ? this._triggers = (/* @__PURE__ */ new Map()).set(e, r) : t.set(e, r), this._size() >= this._growthLimit && this._grow());
|
|
278
292
|
}
|
|
279
293
|
/**
|
|
280
294
|
* Создаёт trigger целого ключа на месте `offset` ряда: в конце ряда либо на
|
|
@@ -282,19 +296,19 @@ class f {
|
|
|
282
296
|
* создаёт, и пустой ряд остаётся пустым.
|
|
283
297
|
*/
|
|
284
298
|
_trackDense(e, s, t) {
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
const o =
|
|
299
|
+
const i = this._triggers;
|
|
300
|
+
if (i !== void 0 && i.size !== 0) {
|
|
301
|
+
const o = i.get(e);
|
|
288
302
|
if (o !== void 0) {
|
|
289
303
|
t._readSignalNode(o);
|
|
290
304
|
return;
|
|
291
305
|
}
|
|
292
306
|
}
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
307
|
+
const r = t._trackCounterNode(this._source);
|
|
308
|
+
if (r === void 0)
|
|
295
309
|
return;
|
|
296
310
|
const n = this._dense;
|
|
297
|
-
s === n.length ? (s === 0 && (this._denseBase = e + 0), n.push(
|
|
311
|
+
s === n.length ? (s === 0 && (this._denseBase = e + 0), n.push(r)) : n[s] = r, this._denseCount++, this._size() >= this._growthLimit && this._grow();
|
|
298
312
|
}
|
|
299
313
|
/**
|
|
300
314
|
* Подписывает активного потребителя на trigger ключа-объекта: связь с ним
|
|
@@ -304,10 +318,10 @@ class f {
|
|
|
304
318
|
if (this._trackedKey = e, s !== void 0)
|
|
305
319
|
t._readSignalNode(s);
|
|
306
320
|
else {
|
|
307
|
-
const
|
|
308
|
-
if (
|
|
309
|
-
const
|
|
310
|
-
|
|
321
|
+
const i = t._trackCounterNode(this._objectHooks);
|
|
322
|
+
if (i !== void 0) {
|
|
323
|
+
const r = this._triggers;
|
|
324
|
+
r === void 0 ? this._triggers = (/* @__PURE__ */ new Map()).set(e, i) : r.set(e, i), this._size() >= this._growthLimit && this._grow();
|
|
311
325
|
}
|
|
312
326
|
}
|
|
313
327
|
this._trackedKey = void 0;
|
|
@@ -330,23 +344,23 @@ class f {
|
|
|
330
344
|
* значения ищется после пробуждения прежнего, которое могло изменить индекс.
|
|
331
345
|
*/
|
|
332
346
|
_wakePair(e, s, t) {
|
|
333
|
-
let
|
|
347
|
+
let i = !1, r;
|
|
334
348
|
const n = this._find(e);
|
|
335
349
|
if (n !== void 0)
|
|
336
350
|
try {
|
|
337
351
|
this._bump(e, n, t);
|
|
338
352
|
} catch (h) {
|
|
339
|
-
|
|
353
|
+
i = !0, r = h;
|
|
340
354
|
}
|
|
341
355
|
const o = this._find(s);
|
|
342
356
|
if (o !== void 0)
|
|
343
357
|
try {
|
|
344
358
|
this._bump(s, o, t);
|
|
345
359
|
} catch (h) {
|
|
346
|
-
throw
|
|
360
|
+
throw i ? new AggregateError([r, h], "[Raph] Selector notification failed.") : h;
|
|
347
361
|
}
|
|
348
|
-
if (
|
|
349
|
-
throw
|
|
362
|
+
if (i)
|
|
363
|
+
throw r;
|
|
350
364
|
}
|
|
351
365
|
/**
|
|
352
366
|
* Сдвигает счётчик trigger: его потребители получают invalidation. Trigger
|
|
@@ -388,10 +402,10 @@ class f {
|
|
|
388
402
|
* вычислить, считается изменившимся: потребитель встретит то же исключение
|
|
389
403
|
* в собственном чтении. Сбои копятся в `errors`; возвращается их список.
|
|
390
404
|
*/
|
|
391
|
-
_wakeChanged(e, s, t,
|
|
405
|
+
_wakeChanged(e, s, t, i, r, n) {
|
|
392
406
|
let o = !0;
|
|
393
407
|
try {
|
|
394
|
-
o =
|
|
408
|
+
o = r(e, t) !== r(e, i);
|
|
395
409
|
} catch (h) {
|
|
396
410
|
(n ??= []).push(h);
|
|
397
411
|
}
|
|
@@ -410,9 +424,9 @@ class f {
|
|
|
410
424
|
*/
|
|
411
425
|
_find(e) {
|
|
412
426
|
if (typeof e == "number") {
|
|
413
|
-
const t = this._dense,
|
|
414
|
-
if (
|
|
415
|
-
return t[
|
|
427
|
+
const t = this._dense, i = this._denseBase, r = e - i;
|
|
428
|
+
if (r >= 0 && r < t.length && r === (r | 0) && i + r === e)
|
|
429
|
+
return t[r];
|
|
416
430
|
}
|
|
417
431
|
const s = this._triggers;
|
|
418
432
|
return s === void 0 ? void 0 : s.get(e);
|
|
@@ -430,10 +444,10 @@ class f {
|
|
|
430
444
|
*/
|
|
431
445
|
_forget(e) {
|
|
432
446
|
if (typeof e == "number") {
|
|
433
|
-
const t = this._dense,
|
|
434
|
-
if (
|
|
435
|
-
if (t[
|
|
436
|
-
t[
|
|
447
|
+
const t = this._dense, i = this._denseBase, r = e - i;
|
|
448
|
+
if (r >= 0 && r < t.length && r === (r | 0) && i + r === e) {
|
|
449
|
+
if (t[r] !== void 0) {
|
|
450
|
+
t[r] = void 0;
|
|
437
451
|
const n = --this._denseCount;
|
|
438
452
|
(n === 0 || t.length > (n * 2 + 32) * 2) && this._settleDense();
|
|
439
453
|
}
|
|
@@ -467,37 +481,44 @@ class f {
|
|
|
467
481
|
e.length = 0;
|
|
468
482
|
return;
|
|
469
483
|
}
|
|
470
|
-
let t = e.length,
|
|
471
|
-
for (;
|
|
472
|
-
|
|
473
|
-
for (; t >
|
|
484
|
+
let t = e.length, i = 0;
|
|
485
|
+
for (; i < t && e[i] === void 0; )
|
|
486
|
+
i++;
|
|
487
|
+
for (; t > i && e[t - 1] === void 0; )
|
|
474
488
|
t--;
|
|
475
|
-
if (t -
|
|
476
|
-
const
|
|
477
|
-
for (let o =
|
|
489
|
+
if (t - i > s * 2 + 32) {
|
|
490
|
+
const r = this._denseBase, n = this._triggers ??= /* @__PURE__ */ new Map();
|
|
491
|
+
for (let o = i; o < t; o++) {
|
|
478
492
|
const h = e[o];
|
|
479
|
-
h !== void 0 && n.set(
|
|
493
|
+
h !== void 0 && n.set(r + o, h);
|
|
480
494
|
}
|
|
481
495
|
e.length = 0, this._denseCount = 0;
|
|
482
496
|
return;
|
|
483
497
|
}
|
|
484
|
-
|
|
498
|
+
i !== 0 && (e.copyWithin(0, i, t), this._denseBase += i), e.length = t - i;
|
|
485
499
|
}
|
|
486
500
|
}
|
|
487
|
-
function
|
|
488
|
-
|
|
501
|
+
function u(d) {
|
|
502
|
+
const e = (s) => d._test(s);
|
|
503
|
+
return g.set(e, d), e;
|
|
504
|
+
}
|
|
505
|
+
const g = /* @__PURE__ */ new WeakMap();
|
|
506
|
+
function l(d) {
|
|
507
|
+
if (typeof d == "function")
|
|
508
|
+
return g.get(d)?._inspect();
|
|
489
509
|
}
|
|
490
|
-
function a(
|
|
510
|
+
function a(d, e) {
|
|
491
511
|
return {
|
|
492
512
|
token: e,
|
|
493
513
|
onDependency: () => {
|
|
494
|
-
const s =
|
|
514
|
+
const s = d._trackedKey;
|
|
495
515
|
return () => {
|
|
496
|
-
|
|
516
|
+
d._edgeDetached(s);
|
|
497
517
|
};
|
|
498
518
|
}
|
|
499
519
|
};
|
|
500
520
|
}
|
|
501
521
|
export {
|
|
502
|
-
f as RuntimeSelector
|
|
522
|
+
f as RuntimeSelector,
|
|
523
|
+
l as inspectSelector
|
|
503
524
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../reactivity/reactive-object.cjs"),r=Object.freeze({configure:e.configureReactiveObjectPolicy,dispose:e.disposeReactiveObjectContext,reactive(t,c){return e.reactiveObject(t,c,()=>t._createReactivePropertySourceBridge())}});exports.RUNTIME_OBJECT_SUPPORT=r;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { disposeReactiveObjectContext as c, configureReactiveObjectPolicy as r, reactiveObject as o } from "../../reactivity/reactive-object.js";
|
|
2
|
+
const a = /* @__PURE__ */ Object.freeze({
|
|
3
|
+
configure: r,
|
|
4
|
+
dispose: c,
|
|
5
|
+
reactive(e, t) {
|
|
6
|
+
return o(e, t, () => e._createReactivePropertySourceBridge());
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export {
|
|
10
|
+
a as RUNTIME_OBJECT_SUPPORT
|
|
11
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../reactivity/engine-core.cjs"),k=require("../errors.cjs"),O=require("../phases/RaphPhaseTaskRecord.cjs"),R=require("./RaphWorkGraph.cjs");let c,a;function T(n){return{schedule:n,dispose:g}}let v=0;function A(n){n.firstSub!==null&&++v}function E(n,e,t){n.firstSub===null&&t.delete(e)}const h=Object.freeze({}),S=Object.freeze({schedule:g,dispose:g}),m=64;class N{constructor(e){this.items=[e],this.shared=!1}detach(){const e=this.items.slice();return this.items=e,this.shared=!1,e}}class _ extends R.RaphProducer{constructor(e,t,r,s){super(e,t,r),this._value=s,this._node=void 0,this._previousSource=void 0,this._writeTaps=void 0,this.source=this}get token(){return this}get dependencyOwner(){return this.owner}toJSON(){let e=0;for(let t=this._previousSource;t!==void 0&&e<m;t=t._previousSource)++e;return{kind:this.kind,owner:this.owner.id,index:e,revision:this.revision,disposed:this.disposed}}get(){const e=this.owner,t=e.runtime._getReactivity();w(t,e),(e._disposed||e._disposing)&&e._assertAlive();const r=this._node;if(r!==void 0)return t._readSignalNode(r);const s=this._value,i=t._trackSignalNode(s,this);return i!==void 0&&(this._node=i,this._value=void 0),s}peek(){const e=this.owner,t=e.runtime._getReactivity();f(t._lifecycle),e._assertAlive();const r=this._node;return r===void 0?this._value:t._peekSignalNode(r)}set(e){const t=this.owner,r=t.runtime,s=r._getReactivity()._lifecycle,i=s.assertWriteAllowed;i===void 0?(f(s),t._assertAlive()):(t._assertAlive(),i()),r._enterWrite();try{this._write(e)}catch(o){throw r._failWrite(o)}r._exitWrite()}_writeInBoundary(e){const t=this.owner;f(t.runtime._getReactivity()._lifecycle),t._assertAlive(),this._write(e)}_addWriteTap(e){const t=this._writeTaps;if(t===void 0){e._tapSlot=0,this._writeTaps=new N(e);return}const r=t.shared?t.detach():t.items;e._tapSlot=r.length,r.push(e)}_removeWriteTap(e){const t=this._writeTaps;if(t===void 0)return;const r=e._tapSlot;if(r<0||t.items[r]!==e)return;if(e._tapSlot=-1,t.items.length===1){this._writeTaps=void 0;return}const s=t.shared?t.detach():t.items,i=s.pop();i!==e&&(s[r]=i,i._tapSlot=r)}onChange(e,t,r){this.owner.runtime._getWorkGraph()._notifyValueWrite(this,e,t,r)}onDispose(e){this.owner.runtime._getWorkGraph()._disposeProducer(this,e)}_findConsumerOwner(e,t){const r=this._writeTaps;if(r!==void 0){const i=r.items;for(let o=0;o<i.length;o++){const u=i[o]._tapOwner;if(e(u,t))return u}}const s=this._node;return s===void 0?void 0:this.owner.runtime._getReactivity()._findSubscriberOwner(s,e,t)}_finalizeSource(){if(this.disposed)return!0;this._value=void 0,this._writeTaps=void 0;const e=this._node,t=this.owner.runtime._getReactivity();let r;try{this.onDispose(e!==void 0&&t._signalNodeHasSubscribers(e))}catch(s){(r??=[]).push(s)}if(e!==void 0){this._node=void 0;try{t._releaseSignalNode(e)}catch(s){(r??=[]).push(s)}}if(r!==void 0)throw r.length===1?r[0]:new AggregateError(r,"Owned signal disposal failed.");return!0}_write(e){const t=this._writeTaps;if(t!==void 0){this._writeTapped(e,t);return}const r=this._node;if(r!==void 0){const i=this.owner.runtime,o=i._getReactivity(),u=o._visibleSignalValue(r);u!==e&&i._getWorkGraph()._notifyValueWrite(this,u,e,r.firstSub!==null),o._writeSignalNode(r,e);return}const s=this._value;s!==e&&(this.owner.runtime._getWorkGraph()._notifyValueWrite(this,s,e,!1),this._value=e)}_writeTapped(e,t){const r=this._node,s=this.owner.runtime._getReactivity(),i=r===void 0?this._value:s._visibleSignalValue(r);if(i===e)return;const o=t.items;t.shared=!0;let u=r!==void 0&&s._signalNodeHasSubscribers(r);for(let l=0;!u&&l<o.length;l++)u=o[l]._observesWrites();this.onChange(i,e,u);let d;if(r===void 0)this._value=e;else try{s._writeSignalNode(r,e)}catch(l){d=[l]}for(let l=0;l<o.length;l++)try{o[l]._afterSourceWrite(i,e)}catch(y){(d??=[]).push(y)}if(d!==void 0)throw d.length===1?d[0]:new AggregateError(d,"[Raph] Signal write and its observers failed.")}}class p extends b.ReactivityEngine{constructor(e,t={},r){super({...t.adaptiveDependencyIndex===void 0?{}:{adaptiveDependencyIndex:t.adaptiveDependencyIndex},effectScheduler:{bind:T}}),this._lifecycle=e,this._selectors=r,this._phaseBody=()=>{const s=this._activeEffectTask(),i=s.consumerOwner,o=c,u=a;c=e,a=i;let d;try{const l=s.effect;d=l(s.state&O.TASK_TASKLESS?s.group:s.task)}finally{c=o,a=u}return typeof d=="function"?W(this,d):d},p._releasedShapeAnchor??=C(this)}untrackedWithOwner(e){const t=c,r=a;c=void 0,a=void 0;try{return this.untracked(e)}finally{c=t,a=r}}_probeReadsWithOwner(e){const t=c,r=a;c=void 0,a=void 0;try{return this._probeReads(e)}finally{c=t,a=r}}_applyUntrackedWithOwner(e,t,r){const s=c,i=a;c=void 0,a=void 0;try{return this._isTracking()?this.untracked(()=>Reflect.apply(e,r,t)):Reflect.apply(e,r,t)}finally{c=s,a=i}}_runTaskEffectUntracked(e){const t=c,r=a;c=void 0,a=void 0;try{this._finishTaskEffectRun(e)}finally{c=t,a=r}}getActiveOwner(){return c===void 0?void 0:c.owner}getActiveConsumerOwner(){return a}hasActiveContext(){return c!==void 0||this._isTracking()}runWithOwner(e,t,r){const s=c,i=a;c=e,a=e===void 0?void 0:t;try{return r()}finally{c=s,a=i}}_findSignalConsumerOwner(e,t,r){for(let s=e._lastOwnedSource();s!==void 0;s=s._previousSource){if(!(s instanceof _)&&!this._selectors?.is(s))continue;const i=s._findConsumerOwner(t,r);if(i!==void 0)return i}}_assertTrackedRead(e){w(this,e)}_hasSingleSubscriber(e){const t=e.firstSub;return t!==null&&t===e.lastSub}_countObserved(e,t){let r=0;for(let s=0;s<e.length;s++){const i=e[s];i!==void 0&&i.firstSub!==null&&++r}return t!==void 0&&t.size!==0&&(v=0,t.forEach(A),r+=v),r}_dropUnobserved(e,t){let r=0;for(let s=0;s<e.length;s++){const i=e[s];i!==void 0&&(i.firstSub===null?e[s]=void 0:++r)}return t!==void 0&&t.size!==0&&t.forEach(E),r}selectorForOwner(e,t,r){if(this._selectors===void 0)throw new TypeError("[Raph] Selectors require the full execution profile.");if(!(e instanceof _))throw new TypeError("[Raph] selector() source must be a writable Runtime signal.");const s=r?.equals;if(s!==void 0&&typeof s!="function")throw new TypeError("[Raph] selector() equals must be a function.");const i=e.owner;if(i.runtime!==t.runtime)throw new k.RaphCrossRuntimeError("[Raph] selector() source belongs to another runtime.");i._assertAlive(),this._lifecycle.assertDependencyAllowed(i,t);const o=this._selectors.create(t,this,e,s);try{t._adoptSourceEntry(o)}catch(u){throw o._finalizeSource(),u}return o}signalForOwner(e,t,r="producer",s=!0){const i=new _(t,r,s,e);return t._adoptSourceEntry(i),i}computedForOwner(e,t,r){const s=this._lifecycle,i=t._adoptSource(this._ownedComputed(e,r));return{get:()=>{w(this,t),t._assertAlive();const o=i.get();return t._assertAlive(),o},peek(){f(s),t._assertAlive();const o=i.peek();return t._assertAlive(),o}}}}p._releasedShapeAnchor=void 0;function C(n){let e,t;const r=n._allocateTaskEffect(()=>{e=n._trackSignalNode(void 0,h),t=n._trackSignalNode(void 0,h)},S);n._requestTaskEffect(r,!1),n._beginTaskEffectRun(r),n._finishTaskEffectRun(r);const s=e.firstSub;n._disposeTaskEffect(r),n.batch(()=>n._writeSignalNode(t,0)),n._releaseSignalNode(e),n._releaseSignalNode(t);let i,o;const u=n._allocateTaskEffect(()=>{i=n._trackCounterNode(h),o=n._trackCounterNode(h)},S);return n._requestTaskEffect(u,!1),n._beginTaskEffectRun(u),n._finishTaskEffectRun(u),n.batch(()=>{n._bumpSignalNode(o)}),n._disposeTaskEffect(u),n._releaseSignalNode(i),n._releaseSignalNode(o),{source:e,written:t,edge:s,consumer:r,counter:i,bumped:o}}function W(n,e){return()=>n.untrackedWithOwner(e)}function f(n){n.owner===void 0&&n.throwDisposed()}function w(n,e){const t=n._lifecycle;t.owner===void 0&&t.throwDisposed();const r=c;if(r!==void 0){r!==t&&t.throwCrossRuntime(r.owner);const i=a;i!==void 0&&i!==e&&t.assertDependencyAllowed(e,i);return}const s=n._activeSubscriberOwner();s!==void 0&&t.assertDependencyAllowed(e,s)}function g(){}exports.RuntimeReactivity=p;exports.RuntimeSignal=_;exports.SIGNAL_INDEX_LIMIT=m;
|