@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
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Raph has three layers that you can use independently: a reactive graph,
|
|
4
4
|
a runtime that owns and schedules work, and a state machine for processes
|
|
5
5
|
with explicit transitions. This guide builds them up in that order.
|
|
6
|
+
The optional observable entrypoint adds native values, class annotations,
|
|
7
|
+
and custom adapters to the runtime's existing graph and lifecycle.
|
|
6
8
|
|
|
7
9
|
```sh
|
|
8
10
|
npm install @raphy-js/raph@dev
|
|
@@ -397,6 +399,81 @@ increment()
|
|
|
397
399
|
When the runtime is created with `enforceActions: true`, writes are
|
|
398
400
|
allowed only inside an action or batch.
|
|
399
401
|
|
|
402
|
+
### 2.8. Native values and objects
|
|
403
|
+
|
|
404
|
+
Import the optional layer when you need property assignments or mutable native
|
|
405
|
+
values instead of explicit signal access:
|
|
406
|
+
|
|
407
|
+
```ts
|
|
408
|
+
import { RaphRuntime } from '@raphy-js/raph/runtime'
|
|
409
|
+
import { observable } from '@raphy-js/raph/observable'
|
|
410
|
+
|
|
411
|
+
const runtime = new RaphRuntime({ enforceActions: true })
|
|
412
|
+
runtime.definePhases([{ name: 'render' }])
|
|
413
|
+
const store = observable(runtime, {
|
|
414
|
+
price: 12.5,
|
|
415
|
+
updated: new Date(0),
|
|
416
|
+
labels: new Map<string, string>(),
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
const stop = runtime.rootScope.effect('render', () => {
|
|
420
|
+
console.log(store.price.toFixed(2), store.updated.toISOString())
|
|
421
|
+
})
|
|
422
|
+
runtime.batch(() => {
|
|
423
|
+
store.price = 15
|
|
424
|
+
store.updated.setTime(1000)
|
|
425
|
+
store.labels.set('status', 'ready')
|
|
426
|
+
})
|
|
427
|
+
stop()
|
|
428
|
+
runtime.dispose()
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Object fields retain their original TypeScript types. Objects and arrays, Map,
|
|
432
|
+
Set, weak collections, Date, URL, and URLSearchParams use their native operations
|
|
433
|
+
through a stable view owned by the passed runtime's root scope. Reads track
|
|
434
|
+
dependencies; writes follow the same action, phase, and disposal rules as other
|
|
435
|
+
runtime state. Deep observation is the default; `{ deep: false }` observes the
|
|
436
|
+
root value without wrapping children. The depth is fixed on first connection.
|
|
437
|
+
|
|
438
|
+
Mutating a raw alias bypasses the view. A Date stored in an ordinary signal
|
|
439
|
+
does not become observable automatically: create its observable view explicitly.
|
|
440
|
+
Native subclasses and hidden mutations use a custom adapter.
|
|
441
|
+
|
|
442
|
+
### 2.9. Class fields, computed getters, and methods
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
import type { RaphRuntime } from '@raphy-js/raph/runtime'
|
|
446
|
+
import { makeAutoObservable } from '@raphy-js/raph/observable'
|
|
447
|
+
|
|
448
|
+
class Counter {
|
|
449
|
+
count = 0
|
|
450
|
+
get doubled() { return this.count * 2 }
|
|
451
|
+
increment() { this.count++ }
|
|
452
|
+
|
|
453
|
+
constructor(runtime: RaphRuntime) {
|
|
454
|
+
makeAutoObservable(runtime, this, {}, { autoBind: true })
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Fields remain ordinary reads and assignments. Getters are cached while observed;
|
|
460
|
+
methods become autoActions, retaining tracked reads when called from a
|
|
461
|
+
computation and opening an action when called outside it. `autoBind` preserves
|
|
462
|
+
the instance when a method is passed as a callback. For explicit annotations
|
|
463
|
+
or inheritance, use `makeObservable`. Uninitialized fields and JavaScript
|
|
464
|
+
`#private` mutations are not inferred. This is Raph's explicit runtime contract,
|
|
465
|
+
not complete MobX compatibility.
|
|
466
|
+
|
|
467
|
+
Two more helpers extend the same layer:
|
|
468
|
+
|
|
469
|
+
- `observableBuffer(runtime, value)` keeps a native TypedArray/DataView/buffer
|
|
470
|
+
suitable for WebGL. `read`, `mutate`, and `notify` use explicit byte ranges;
|
|
471
|
+
external or worker writes require `notify` and application synchronization.
|
|
472
|
+
- `defineObservableAdapter({ create(raw, context) { ... } })` connects a custom
|
|
473
|
+
type through `track`, `mutate`, `notify`, `onObserved`, and `onDispose`. The
|
|
474
|
+
adapter selects events and granularity; it does not scan hidden internal state.
|
|
475
|
+
Pass it to `observable(runtime, raw, { adapter })` to create the view.
|
|
476
|
+
|
|
400
477
|
## 3. Why use a state machine?
|
|
401
478
|
|
|
402
479
|
You could model a dialog with three signals:
|
|
@@ -1088,9 +1165,32 @@ often does.
|
|
|
1088
1165
|
| --- | --- |
|
|
1089
1166
|
| `@raphy-js/raph/reactivity` | Standalone reactive graph |
|
|
1090
1167
|
| `@raphy-js/raph/runtime` | Ownership, nodes, phases, and scheduling |
|
|
1168
|
+
| `@raphy-js/raph/observable` | Native observable values, class annotations, buffers, and adapters |
|
|
1091
1169
|
| `@raphy-js/raph/machine` | Pure machine model and runtime execution |
|
|
1092
1170
|
| `@raphy-js/raph/machine/testing` | Inspection, coverage, and manual clock |
|
|
1093
1171
|
|
|
1094
1172
|
The complete Raph package also exposes paths and other runtime APIs.
|
|
1095
1173
|
This guide follows the signal-to-machine route; each entrypoint exports
|
|
1096
1174
|
its public TypeScript declarations.
|
|
1175
|
+
|
|
1176
|
+
## Execution runtime
|
|
1177
|
+
|
|
1178
|
+
`@raphy-js/raph/execution` exposes `RaphExecutionRuntime`: the same reactive graph, ownership, phases, actions and disposal used by the full runtime, with Kernel, paths and debug facilities excluded from this entrypoint. `RaphRuntime` remains the default full API.
|
|
1179
|
+
|
|
1180
|
+
Adapter types retain their concrete runtime with `Runtime extends RaphExecution<Runtime>`. The type-only family is parameterized because callbacks and child operations accept tasks and owners belonging to that runtime. `RaphEffectScope<Runtime>` carries the same profile and defaults to the full runtime.
|
|
1181
|
+
|
|
1182
|
+
## Compact execution for a known composition
|
|
1183
|
+
|
|
1184
|
+
`@raphy-js/raph/compact` exports `RaphCompactExecutionRuntime`. It uses the same
|
|
1185
|
+
signal engine, ownership, phases, producer watchers, aggregates and cleanup as
|
|
1186
|
+
the existing runtimes. This profile omits Proxy objects and key selectors;
|
|
1187
|
+
`reactiveObjects` and `selectors` are typed as `false`. Concrete `reactive()`
|
|
1188
|
+
and owner `selector()` calls are rejected by TypeScript and diagnosed for
|
|
1189
|
+
JavaScript callers. Tree observation remains available. Full and the previous
|
|
1190
|
+
execution entry retain their existing selector behavior.
|
|
1191
|
+
|
|
1192
|
+
`RaphRuntime`, `RaphExecutionRuntime` and standalone `RaphReactivity` retain
|
|
1193
|
+
`reactive()` and their existing public operations. Full and compact runtimes do
|
|
1194
|
+
not share application state. Choose compact only when the host proves that the
|
|
1195
|
+
composition does not need omitted APIs; authored code uses Full unless it
|
|
1196
|
+
explicitly selects an execution contract. Monta owns that automatic selection.
|
package/dist/api/Raph.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { DerivedOptions, RaphDerivedHandle } from '../path/derived/RaphDerivedHandle';
|
|
2
|
-
import { DataPathDef, PathOptions } from '../path/path.types';
|
|
3
|
-
import { RaphKernel, RaphKernelOptions, RaphKernelRoot } from '../path/RaphKernel';
|
|
4
|
-
import { ScopeNode } from '../reactivity/scope';
|
|
5
|
-
import { Disposer, ReadonlySignal, Signal, WatchOptions, WatchSource, WatchValue, WritableComputedOptions } from '../reactivity/types';
|
|
6
|
-
import { RaphRuntimeDebug } from '../runtime/diagnostics/RaphDebug';
|
|
7
|
-
import { NodeOptions, RaphNode } from '../runtime/ownership/RaphNode';
|
|
8
|
-
import { RaphScope } from '../runtime/ownership/RaphScope';
|
|
9
|
-
import { FrameLoopLease, RaphAggregateSource, RaphEffectOptions, RaphPhase, RaphPhaseEffect, RaphWatchOptions, RaphWatchSource } from '../runtime/phases/phase.types';
|
|
10
|
-
import { RaphRuntimeMeta, RaphRuntimeOptions, RaphRuntime } from '../runtime/RaphRuntime';
|
|
11
|
-
import { PathHandle } from '../runtime/reactivity/PathHandle';
|
|
12
|
-
import { RaphAggregate } from '../runtime/reactivity/RaphWorkGraph';
|
|
13
|
-
import { ConfiguredRaph, RaphFlatConfigureOptions, RaphInstance, RaphInstanceDefinitions, RaphInstancesConfigureOptions, RaphReactivityInstanceOptions, StrictRaphConfigureOptions } from './types';
|
|
14
|
-
import { collectionByKey, filterByKey, full } from '../path/derived/derived-strategy.utils';
|
|
15
|
-
import { RaphReactivityInstance } from './RaphReactivityInstance';
|
|
1
|
+
import { DerivedOptions, RaphDerivedHandle } from '../path/derived/RaphDerivedHandle.js';
|
|
2
|
+
import { DataPathDef, PathOptions } from '../path/path.types.js';
|
|
3
|
+
import { RaphKernel, RaphKernelOptions, RaphKernelRoot } from '../path/RaphKernel.js';
|
|
4
|
+
import { ScopeNode } from '../reactivity/scope.js';
|
|
5
|
+
import { Disposer, ReadonlySignal, Signal, WatchOptions, WatchSource, WatchValue, WritableComputedOptions } from '../reactivity/types.js';
|
|
6
|
+
import { RaphRuntimeDebug } from '../runtime/diagnostics/RaphDebug.js';
|
|
7
|
+
import { NodeOptions, RaphNode } from '../runtime/ownership/RaphNode.js';
|
|
8
|
+
import { RaphScope } from '../runtime/ownership/RaphScope.js';
|
|
9
|
+
import { FrameLoopLease, RaphAggregateSource, RaphEffectOptions, RaphPhase, RaphPhaseEffect, RaphWatchOptions, RaphWatchSource } from '../runtime/phases/phase.types.js';
|
|
10
|
+
import { RaphRuntimeMeta, RaphRuntimeOptions, RaphRuntime } from '../runtime/RaphRuntime.js';
|
|
11
|
+
import { PathHandle } from '../runtime/reactivity/PathHandle.js';
|
|
12
|
+
import { RaphAggregate } from '../runtime/reactivity/RaphWorkGraph.js';
|
|
13
|
+
import { ConfiguredRaph, RaphFlatConfigureOptions, RaphInstance, RaphInstanceDefinitions, RaphInstancesConfigureOptions, RaphReactivityInstanceOptions, StrictRaphConfigureOptions } from './types.js';
|
|
14
|
+
import { collectionByKey, filterByKey, full } from '../path/derived/derived-strategy.utils.js';
|
|
15
|
+
import { RaphReactivityInstance } from './RaphReactivityInstance.js';
|
|
16
16
|
type WithoutRuntimePathHandle<Source> = Source extends PathHandle<unknown> ? never : Source extends readonly unknown[] ? {
|
|
17
17
|
[Key in keyof Source]: Source[Key] extends PathHandle<unknown> ? never : Source[Key];
|
|
18
18
|
} : Source;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RaphRuntimeOptions, RaphRuntime } from '../runtime/RaphRuntime';
|
|
2
|
-
import { RaphConfigureOptions, RaphInstance, RaphReactivityInstanceOptions } from './types';
|
|
3
|
-
import { RaphKernel } from '../path/RaphKernel';
|
|
4
|
-
import { RaphReactivityInstance } from './RaphReactivityInstance';
|
|
1
|
+
import { RaphRuntimeOptions, RaphRuntime } from '../runtime/RaphRuntime.js';
|
|
2
|
+
import { RaphConfigureOptions, RaphInstance, RaphReactivityInstanceOptions } from './types.js';
|
|
3
|
+
import { RaphKernel } from '../path/RaphKernel.js';
|
|
4
|
+
import { RaphReactivityInstance } from './RaphReactivityInstance.js';
|
|
5
5
|
/**
|
|
6
6
|
* Владеет registry, default pointer и lifecycle одной facade generation.
|
|
7
7
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Disposer, ReadonlySignal, Signal, WatchCallback, WatchOptions, WatchSource, WritableComputedOptions } from '../reactivity/types';
|
|
2
|
-
import { RaphReactivityInstanceOptions } from './types';
|
|
3
|
-
import { RaphReactivity } from '../reactivity/engine';
|
|
4
|
-
import { ScopeNode } from '../reactivity/scope';
|
|
1
|
+
import { Disposer, ReadonlySignal, Signal, WatchCallback, WatchOptions, WatchSource, WritableComputedOptions } from '../reactivity/types.js';
|
|
2
|
+
import { RaphReactivityInstanceOptions } from './types.js';
|
|
3
|
+
import { RaphReactivity } from '../reactivity/engine.js';
|
|
4
|
+
import { ScopeNode } from '../reactivity/scope.js';
|
|
5
5
|
/**
|
|
6
6
|
* Управляемый pure-reactivity instance одной facade session.
|
|
7
7
|
*/
|
package/dist/api/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { RaphKernel } from '../path/RaphKernel';
|
|
2
|
-
import { RaphReactivity } from '../reactivity/engine';
|
|
3
|
-
import { ScopeNode } from '../reactivity/scope';
|
|
4
|
-
import { Disposer } from '../reactivity/types';
|
|
5
|
-
import { RaphNode } from '../runtime/ownership/RaphNode';
|
|
6
|
-
import { RaphScope } from '../runtime/ownership/RaphScope';
|
|
7
|
-
import { RaphAggregateSource, RaphEffectOptions, RaphPhase, RaphPhaseEffect, RaphWatchOptions, RaphWatchSource } from '../runtime/phases/phase.types';
|
|
8
|
-
import { RaphRuntime, RaphRuntimeOptions } from '../runtime/RaphRuntime';
|
|
9
|
-
import { RaphAggregate } from '../runtime/reactivity/RaphWorkGraph';
|
|
10
|
-
import { RaphReactivityInstance } from './RaphReactivityInstance';
|
|
1
|
+
import { RaphKernel } from '../path/RaphKernel.js';
|
|
2
|
+
import { RaphReactivity } from '../reactivity/engine.js';
|
|
3
|
+
import { ScopeNode } from '../reactivity/scope.js';
|
|
4
|
+
import { Disposer } from '../reactivity/types.js';
|
|
5
|
+
import { RaphNode } from '../runtime/ownership/RaphNode.js';
|
|
6
|
+
import { RaphScope } from '../runtime/ownership/RaphScope.js';
|
|
7
|
+
import { RaphAggregateSource, RaphEffectOptions, RaphPhase, RaphPhaseEffect, RaphWatchOptions, RaphWatchSource } from '../runtime/phases/phase.types.js';
|
|
8
|
+
import { RaphRuntime, RaphRuntimeOptions } from '../runtime/RaphRuntime.js';
|
|
9
|
+
import { RaphAggregate } from '../runtime/reactivity/RaphWorkGraph.js';
|
|
10
|
+
import { RaphReactivityInstance } from './RaphReactivityInstance.js';
|
|
11
11
|
export interface RaphReactiveApi {
|
|
12
12
|
readonly signal: RaphReactivity['signal'];
|
|
13
13
|
readonly reactive: RaphReactivity['reactive'];
|
|
@@ -148,7 +148,7 @@ export interface ConfiguredRaphRegistry<Instances extends Record<string, RaphIns
|
|
|
148
148
|
readonly configured: true;
|
|
149
149
|
readonly defaultInstanceId: keyof Instances & string | undefined;
|
|
150
150
|
createReactivity: (options?: RaphReactivityInstanceOptions) => RaphReactivityInstance;
|
|
151
|
-
createKernel: (options?: ConstructorParameters<typeof import('../path/RaphKernel').RaphKernel>[0]) => RaphKernel;
|
|
151
|
+
createKernel: (options?: ConstructorParameters<typeof import('../path/RaphKernel.js').RaphKernel>[0]) => RaphKernel;
|
|
152
152
|
createRuntime: (options?: RaphRuntimeOptions) => RaphRuntime;
|
|
153
153
|
disposeInstance: <Id extends keyof Instances & string>(id: Id) => boolean;
|
|
154
154
|
getInstance: <Id extends keyof Instances & string>(id: Id) => Instances[Id] | undefined;
|
package/dist/compact.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./debug/runtime/RaphCompactExecutionRuntime.cjs");exports.RaphCompactExecutionRuntime=e.RaphCompactExecutionRuntime;
|
package/dist/compact.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("./scope.cjs"),B=require("./watch.cjs"),S=1,f=2,E=4,p=8,y=16,o=32,d=64,I=128,k=256,h=512,A=1<<17,N=1024,b=4096,_=8192,x=16384,w=32768,m=65536,L=b,T=1e4,g=S|f,W=16;function O(R,e){const t=R.firstSub;if(t===null)return;if(t===R.lastSub)return t.sub===e?t:void 0;const i=R.subSearchCursor??t;if(i.sub===e)return R.subSearchCursor=i.nextSub??t,i;let s=i.nextSub??t;for(;s!==i;){if(s.sub===e)return R.subSearchCursor=s.nextSub??t,s;s=s.nextSub??t}}class H{activeSub=null;probeNode=null;probeDepth=0;batchDepth=0;effectReadIndex=0;effectWriteIndex=0;invalidationDepth=0;dependencyDepth=0;checkingDepth=0;checkRoots=[];flushingEffects=!1;firstEffect;effectQueue=new Array(16).fill(void 0);invalidationStack=new Array(512).fill(null);dependencyStack=[];handleReaders=this.createHandleReaders();effectScheduler;flushEffects;_effectImmediate;constructor(e={}){this.effectScheduler=e.effectScheduler,this._effectImmediate=this.effect.bind(this),this.signal=this.signal.bind(this),this.computed=this.computed.bind(this),this.watch=this.watch.bind(this),this.batch=this.batch.bind(this),this.untracked=this.untracked.bind(this),this.scope=this.scope.bind(this),this._signalAccess=this._signalAccess.bind(this),this._computedAccess=this._computedAccess.bind(this),this._ownedSignal=this._ownedSignal.bind(this),this._ownedComputed=this._ownedComputed.bind(this),this._isTracking=this._isTracking.bind(this),this._isFlushingEffects=this._isFlushingEffects.bind(this),this._startBatch=this._startBatch.bind(this),this._endBatch=this._endBatch.bind(this),this.effect=this.effectScheduler===void 0?this._effectImmediate:this.createScheduledEffect.bind(this),this.flushEffects=this.effectScheduler===void 0?this.flushSyncEffects:this.flushExternalEffects}signal(e){let t=e,i;const s=()=>{const l=i;if(l!==void 0)return this.readSignalValue(l);const n=this.activeSub;return n===null||(i=this.materializeSignal(t,n)),t},r=l=>{const n=i;if(n!==void 0){this.writeSignalValue(n,l);return}t!==l&&(t=l)};return{get:s,peek:this.handleReaders.peek,set:r}}computed(e){if(typeof e=="function")return this.createComputedHandle(e);const t=this.createComputedHandle(e.get);return t.set=e.set,t}effect(e,t){const i=this.allocateGraphRecord(void 0,e,f|S|o,void 0);t!==void 0&&(i.onStop=t);const s=this.activeSub;s!==null&&s.flags&o&&D.appendScopeChild(s,i);try{this.executeEffect(i)}catch(r){try{this.disposeEffect(i)}catch(l){throw new AggregateError([r,l],"Effect registration and cleanup failed.")}throw r}return this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),()=>this.disposeEffect(i)}watch(e,t,i){return B.watchWithReactivity(this.effect,this.untracked,e,t,i)}batch(e){++this.batchDepth;let t;try{t=e()}catch(i){if(!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(s){throw new AggregateError([i,s],"Batch operation and effect queue processing failed.")}throw i}return!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),t}untracked(e){if(this.activeSub===null)return e();const t=this.activeSub;this.activeSub=null;try{return e()}finally{this.activeSub=t}}scope(){return new D.ScopeNode(this)}allocateGraphRecord(e,t,i,s){return{flags:i,firstSub:null,lastSub:null,firstDep:null,tailDep:null,evaluate:t,cachedValue:e,pendingValue:void 0,pendingAuthor:void 0,subSearchCursor:void 0,read:s}}_createReactivePropertySourceBridge(){return{batch:this.batch,startBatch:this._startBatch,endBatch:this._endBatch,create:e=>{if(this.activeSub===null)throw new Error("[Raph] Reactive property source requires a tracked read.");return e===void 0?{firstSub:null,lastSub:null}:{firstSub:null,lastSub:null,flags:h,sourceHooks:e}},createTransient:e=>{if(this.activeSub===null)throw new Error("[Raph] Reactive property source requires a tracked read.");return{firstSub:null,lastSub:null,flags:A,onUnobserved:e}},isTracking:this._isTracking,track:e=>{const t=this.activeSub;t!==null&&this.trackDependency(e,t)},trigger:e=>{const t=e.firstSub;t!==null&&(this.propagateInvalidation(t),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects())},hasMultipleSubscribers:e=>{const t=e;return t.firstSub!==null&&t.firstSub!==t.lastSub},release:e=>this.releaseSourceSubs(e)}}materializeSignal(e,t,i){const s=i===void 0?this.allocateGraphRecord(e,void 0,0,void 0):{flags:h,firstSub:null,lastSub:null,firstDep:null,tailDep:null,evaluate:void 0,cachedValue:e,sourceHooks:i};return t.flags&I?this.appendInitialDependency(s,t):this.trackDependency(s,t),s}createComputedHandle(e,t){const i={flags:t===void 0?y:y|h,firstSub:null,lastSub:null,firstDep:null,tailDep:null,evaluate:e,cachedValue:void 0,pendingValue:void 0,pendingAuthor:void 0,subSearchCursor:void 0,get:this.handleReaders.read,peek:this.handleReaders.peek};return t!==void 0&&(i.sourceHooks=t),i}createScheduledEffect(e,t){const i=this.allocateGraphRecord(void 0,e,f|S|o,void 0);let s=!1;t!==void 0&&(i.onStop=t);const r=this.activeSub;r!==null&&r.flags&o&&D.appendScopeChild(r,i);const l=()=>{if(!(!(i.flags&d)||i.evaluate===void 0)){i.flags&=~d,s=!0;try{this.executeEffect(i)}catch(n){if(!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(a){throw new AggregateError([n,a],"Effect execution and queue processing failed.")}throw n}!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}};try{const n=this.effectScheduler.bind(l);n.cancelPending=()=>i.evaluate===void 0||!s?!1:(this.settleCancelledDependencies(i),i.flags&=~(d|g|E),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),!0),n.rearmPending=()=>{i.evaluate!==void 0&&(i.flags|=f|d,n.schedule())},i.effectTask=n,this.requestEffectTask(i)}catch(n){try{this.disposeEffect(i)}catch(a){throw new AggregateError([n,a],"Effect registration and cleanup failed.")}throw n}return!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),()=>this.disposeEffect(i)}readSignalValue(e){const t=this.activeSub;let i=null;return t!==null&&(i=this.trackDependency(e,t)),e.flags&f&&this.commitSignalValue(e,i),t!==null&&t.flags&x&&t.firstDep===i&&(t.flags|=w),e.cachedValue}writeSignalValue(e,t){if(e.flags&f||this.batchDepth){const s=!!(e.flags&f);if((e.flags&f?e.pendingValue:e.cachedValue)===t)return;if(e.pendingValue=t,e.cachedValue===t)e.flags&=~f,e.pendingAuthor=void 0;else{e.flags|=f;const n=this.activeSub!==null&&this.activeSub.flags&p?this.activeSub:null;s?e.pendingAuthor!==n&&(e.pendingAuthor=null):e.pendingAuthor=n}const l=e.firstSub;l!=null&&(!s||this.activeSub!==null&&this.activeSub.flags&p||e.flags&h)&&this.propagateInvalidation(l,!0);return}if(e.cachedValue===t)return;e.cachedValue=t;const i=e.firstSub;i!=null&&(this.propagateInvalidation(i),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects())}readComputedValue(e){const t=e.flags;if((t&(p|I))===(p|I))throw new Error("Computed value is already being evaluated.");const i=t&(y|g|k|m),s=i===0?e.cachedValue:i&y?this.evaluateFirstValue(e):this.refreshComputedValue(e,t);if(e.evaluate===void 0)return s;const r=this.activeSub;if(r!==null){const l=r.tailDep;r.flags&I?(l===null||l.dep!==e)&&this.appendInitialDependency(e,r):this.trackDependency(e,r)}return s}evaluateFirstValue(e){const t=e.flags&h,i=e.evaluate;e.flags=t|p|I;const s=this.activeSub;this.activeSub=e;let r;try{if(r=i(),e.evaluate!==i)return e.cachedValue=void 0,e.flags=0,r;const l=e.firstDep!==null&&e.firstDep.nextDep===null&&(e.flags&(x|w))===(x|w);if(e.flags=t|(l?m:e.flags&E?f:0),l)return e.cachedValue=r,r}catch(l){throw e.evaluate!==i?(e.cachedValue=void 0,e.flags=0,l):(e.flags=t|k,s!==null&&this.trackDependency(e,s),l)}finally{this.activeSub=s}return e.flags&f?this.refreshComputedValue(e,e.flags):(e.cachedValue=r,r)}refreshComputedValue(e,t,i=null){try{if(t&(f|E|k|m))return this.recomputeValue(e,i),e.cachedValue;const s=e.firstDep;return s!==null&&this.walkDependencyChain(e,s)?this.recomputeValue(e,i):e.flags&=~g,e.cachedValue}catch(s){throw this.activeSub!==null&&this.trackDependency(e,this.activeSub),s}}commitSignalValue(e,t){const i=e.cachedValue;e.cachedValue=e.pendingValue,e.flags&=~f;const s=e.pendingAuthor;return e.pendingAuthor=void 0,i===e.cachedValue?!1:(e.firstSub!==null&&this.confirmSubUpdates(e.firstSub,t,s??null),!0)}trackDependency(e,t){const i=t.tailDep;if(i!==null){const r=i.nextDep;return r!==null&&r.dep===e?(t.tailDep=r,r):i.dep===e?i:this.reconcileDependency(e,t,i,r)}const s=t.firstDep;return s===null?t.tailDep=this.insertDependency(e,t,null):s.dep===e?(t.tailDep=s,s):this.reconcileDependency(e,t,null,s)}reconcileDependency(e,t,i,s){if(t.flags&N){const a=e.subSearchCursor;if(a!==void 0&&a.sub===t&&a.dep===e)return this.reorderDependency(t,a,i),t.tailDep=a,a}let r=0,l=s;for(;l!==null&&r<W;){const a=l;if(a.dep===e)return this.reorderDependency(t,a,i),t.tailDep=a,a;l=a.nextDep,++r}let n=i;for(;n!==null&&r<W;){const a=n;if(a.dep===e)return a;n=a.prevDep,++r}if(l!==null&&!(t.flags&N)){t.flags|=N;for(let c=s;c!==null;c=c.nextDep)c.dep.subSearchCursor=c;const a=e.subSearchCursor;if(a!==void 0&&a.sub===t&&a.dep===e)return this.reorderDependency(t,a,i),t.tailDep=a,a}if(l!==null||n!==null){const a=O(e,t);if(a!==void 0)return this.reorderDependency(t,a,i),t.tailDep=a,a}return s!==null?(t.tailDep=this.reuseDepLink(s,e),s):t.tailDep=this.insertDependency(e,t,i)}appendInitialDependency(e,t){const i=t.tailDep,s=e.lastSub,r={dep:e,sub:t,prevSub:s,nextSub:null,prevDep:i,nextDep:null};return s===null?e.firstSub=r:s.nextSub=r,e.lastSub=r,i===null?t.firstDep=r:i.nextDep=r,t.tailDep=r,e.flags&h&&this.attachDependencyCleanup(r),r}insertDependency(e,t,i){const s=e.lastSub,r={dep:e,sub:t,prevSub:s,nextSub:null,prevDep:i,nextDep:null};s===null?e.firstSub=r:s.nextSub=r,e.lastSub=r;const l=i===null?t.firstDep:i.nextDep;return r.nextDep=l,l!==null&&(l.prevDep=r),i===null?t.firstDep=r:i.nextDep=r,e.flags&h&&this.attachDependencyCleanup(r),r}reuseDepLink(e,t){this.detachSubLink(e);const i=t.lastSub;return e.dep=t,e.prevSub=i,e.nextSub=null,i===null?t.firstSub=e:i.nextSub=e,t.lastSub=e,t.flags&h&&this.attachDependencyCleanup(e),e}reorderDependency(e,t,i){if(t.prevDep===i)return;const s=t.prevDep,r=t.nextDep;s===null?e.firstDep=r:s.nextDep=r,r!==null&&(r.prevDep=s);const l=i===null?e.firstDep:i.nextDep;t.prevDep=i,t.nextDep=l,l!==null&&(l.prevDep=t),i===null?e.firstDep=t:i.nextDep=t}pruneUnreadDependencies(e){const t=e.tailDep;let i=t===null?e.firstDep:t.nextDep;if(i===null)return;t===null?e.firstDep=null:t.nextDep=null;for(let r=i;r!==null;r=r.nextDep)r.prevDep=null;let s;for(;i!==null;){const r=i.nextDep;try{this.detachSubLink(i,!0)}catch(l){this.unlinkSubLink(i,!0),s??=[],s.push(l)}i=r}s!==void 0&&D.throwScopeErrors(s,"Dependency cleanup failed.")}detachSubLink(e,t=!1){let i;e.dep.flags&(h|A)&&(i=this.cleanupSourceDependency(e)),this.unlinkSubLink(e,t||i!==void 0)}cleanupSourceDependency(e){const t=e.dep;if(t.flags&h){const i=e.dependencyCleanup;return e.dependencyCleanup=void 0,i?.(),i}t.firstSub===e&&t.lastSub===e&&t.onUnobserved()}unlinkSubLink(e,t){t&&((e.prevSub===null?e.dep.firstSub!==e:e.prevSub.nextSub!==e)||(e.nextSub===null?e.dep.lastSub!==e:e.nextSub.prevSub!==e))||(e.dep.subSearchCursor===e&&(e.dep.subSearchCursor=e.nextSub??(e.dep.firstSub===e?void 0:e.dep.firstSub??void 0)),e.prevSub===null?e.dep.firstSub=e.nextSub:e.prevSub.nextSub=e.nextSub,e.nextSub===null?e.dep.lastSub=e.prevSub:e.nextSub.prevSub=e.prevSub)}attachDependencyCleanup(e){const i=e.dep.sourceHooks?.onDependency;if(i===void 0)return;const s=e.sub.sourceHooks?.dependencyOwner??e.sub.effectTask?.dependencyOwner;s!==void 0&&(e.dependencyCleanup=i(s))}releaseSourceSubs(e){if(!(e.flags&(h|A))){let s=e.firstSub;for(;s!=null;){const r=s.nextSub,l=s.sub;this.detachDependencyLink(s),this.detachSubLink(s);const n=l.flags;(n&(g|p))===S&&(l.flags=n&~S|f,n&o&&this.enqueueEffect(l,e)),s=r}e.firstSub=e.lastSub=null,e.subSearchCursor=void 0;return}let t=e.firstSub,i;for(;t!=null;){const s=t.nextSub;this.detachDependencyLink(t);try{this.detachSubLink(t,!0)}catch(r){this.unlinkSubLink(t,!0),i??=[],i.push(r)}t=s}e.firstSub=e.lastSub=null,e.subSearchCursor=void 0,i!==void 0&&D.throwScopeErrors(i,"Source dependency cleanup failed.")}detachDependencyLink(e){const t=e.sub,i=e.prevDep,s=e.nextDep;(i===null?t.firstDep!==e:i.nextDep!==e)||(i===null?t.firstDep=s:i.nextDep=s,s!==null&&(s.prevDep=i),t.tailDep===e&&(t.tailDep=i))}enqueueEffect(e,t){const i=t!==void 0&&t.flags&h?t.sourceHooks.token:void 0;i!==void 0&&e.effectTask?.notify?.(i),!(e.flags&d)&&(e.flags|=d,this.effectWriteIndex===0?this.firstEffect=e:this.effectQueue[this.effectWriteIndex]=e,++this.effectWriteIndex)}propagateInvalidation(e,t=!1){this.checkingDepth!==0&&this.markActiveChecks(e);const i=this.invalidationDepth;let s=i;for(let r=e;r!==null;r=r.nextSub){const l=r.sub,n=l.flags;let a=0;if(n&(g|p)?n&p?a=this.invalidateReadDependency(r,l,n):!t&&!(n&f)&&(l.flags=n&~S|f):(a=n&~E|(t?S:f),l.flags=a),a===0){if(n&o&&n&d){const c=r.dep.flags&h?r.dep.sourceHooks.token:void 0;c!==void 0&&l.effectTask?.notify?.(c)}else l.flags&(h|_)&&(l.flags&h&&l.sourceHooks.onInvalidate?.(l.firstSub!==null),l.flags&=~_,l.firstSub!==null&&(this.invalidationStack[s++]=l.firstSub));continue}a&o?(!(a&p)||l.effectTask?.allowScheduleDuringRun===!0)&&this.enqueueEffect(l,r.dep):(!(n&g)&&l.flags&h&&l.sourceHooks.onInvalidate?.(l.firstSub!==null),l.firstSub!==null&&(this.invalidationStack[s++]=l.firstSub))}for(;s!==i;){let r=this.invalidationStack[--s];do{const l=r.sub,n=l.flags;let a=0;if(n&(g|p)?n&p&&(a=this.invalidateReadDependency(r,l,n)):(a=n&~E|S,l.flags=a),a===0){if(n&o&&n&d){const c=r.dep.flags&h?r.dep.sourceHooks.token:void 0;c!==void 0&&l.effectTask?.notify?.(c)}else if(l.flags&(h|_)&&(l.flags&h&&l.sourceHooks.onInvalidate?.(l.firstSub!==null),l.flags&=~_,l.firstSub!==null)){r.nextSub!==null&&(this.invalidationStack[s++]=r.nextSub),r=l.firstSub;continue}}else if(a&o)this.enqueueEffect(l,r.dep);else if(!(n&g)&&l.flags&h&&l.sourceHooks.onInvalidate?.(l.firstSub!==null),l.firstSub!==null){r.nextSub!==null&&(this.invalidationStack[s++]=r.nextSub),r=l.firstSub;continue}r=r.nextSub}while(r!==null)}this.invalidationDepth=i}markActiveChecks(e){const t=new Set;for(let r=0;r<this.checkingDepth;r++)t.add(this.checkRoots[r]);for(let r=0;r<this.dependencyDepth;r++){const l=this.dependencyStack[r];t.add(l.sub),t.add(l.dep)}const i=[e],s=new Set;for(;i.length!==0;)for(let r=i.pop();r!==null;r=r.nextSub){const l=r.sub;s.has(l)||(s.add(l),t.has(l)&&(l.flags|=b),!(l.flags&o)&&l.firstSub!==null&&i.push(l.firstSub))}}invalidateReadDependency(e,t,i){const s=t.tailDep;if(s===null)return 0;if(e!==s){for(let l=e.prevDep;l!==null;l=l.prevDep)if(l===s)return 0}let r=i|E|S;return t===this.activeSub&&!(i&o)&&t.firstDep===e&&e.nextDep===null?r=(r|x)&~w:r&=-49153,t.flags=r,r}confirmSubUpdates(e,t,i=null){for(let s=e;s!==null;s=s.nextSub){if(s===t||s.sub===i)continue;const r=s.sub,l=r.flags;l&f||(r.flags=l&~S|f,l&o?this.enqueueEffect(r,s.dep):l&g||r.flags&h&&r.sourceHooks.onInvalidate?.(r.firstSub!==null))}}recomputeValue(e,t=null){const i=e.cachedValue,s=e.evaluate;e.tailDep=null;const r=e.flags&-119813|p;e.flags=r;const l=this.activeSub;this.activeSub=e;let n;try{n=s()}catch(c){this.failComputedRun(e,s,t,c,l)}this.activeSub=l;const a=e.tailDep;return e.evaluate!==s||(a===null?e.firstDep:a.nextDep)!==null||e.flags&(E|x|w)?this.settleComputedValue(e,t,i,s,r,n):(e.flags=r&-8460,e.cachedValue=n,i===n?!1:(e.firstSub!==null&&this.confirmSubUpdates(e.firstSub,t),!0))}settleComputedValue(e,t,i,s,r,l){for(let n=1;;n++){if(e.evaluate!==s)return e.cachedValue=void 0,e.flags=0,!1;const a=e.tailDep;if((a===null?e.firstDep:a.nextDep)!==null)try{this.pruneUnreadDependencies(e)}catch(u){this.failComputedValue(e,t,u)}if(e.evaluate!==s)return e.cachedValue=void 0,e.flags=0,!1;const c=e.flags&E,V=e.firstDep!==null&&e.firstDep.nextDep===null&&(e.flags&(x|w))===(x|w);if(e.flags=r&-8460,c&&!V){if(e.flags|=f,n===T)return this.failComputedValue(e,t,new Error(`Computed settlement exceeded ${T} attempts.`));s=e.evaluate,e.tailDep=null,r=e.flags&-119813|p,e.flags=r;const u=this.activeSub;this.activeSub=e;try{l=s()}catch(v){this.failComputedRun(e,s,t,v,u)}this.activeSub=u;continue}return V&&(e.flags|=m),e.cachedValue=l,i===l?!1:(e.firstSub!==null&&this.confirmSubUpdates(e.firstSub,t),!0)}}failComputedRun(e,t,i,s,r){try{if(e.evaluate!==t)throw e.cachedValue=void 0,e.flags=0,s;this.failComputedValue(e,i,s)}finally{this.activeSub=r}}failComputedValue(e,t,i){try{this.restoreComputedFailure(e,t)}catch(s){throw new AggregateError([i,s],"Computed evaluation and dependency cleanup failed.")}throw i}restoreComputedFailure(e,t){e.evaluate!==void 0&&(e.flags=e.flags&-118928|k);try{e.evaluate!==void 0&&this.pruneUnreadDependencies(e)}finally{e.evaluate===void 0&&(e.cachedValue=void 0,e.flags=0),t!==null&&this.restoreFailedDependency(t.sub)}}settleCancelledDependencies(e){for(let t=e.firstDep;t!==null;t=t.nextDep){const i=t.dep,s=i.flags;s&(y|g|k)&&(i.evaluate===void 0?s&f&&this.commitSignalValue(i,t):this.refreshComputedValue(i,s,t))}}walkDependencyChain(e,t){const i=e,s=this.dependencyDepth;let r=s,l=!1,n;e.flags&b&&(e.flags&=~b),this.checkRoots[this.checkingDepth++]=e;try{e:for(;;){if(e.flags&b){n??=new Map;const a=(n.get(e)??0)+1;if(n.set(e,a),a>T)throw new Error(`Dependency check exceeded ${T} restarts.`);e.flags&=~b,e.firstDep!==null&&(t=e.firstDep)}if(e.flags&f)l=!0;else{const a=t.dep,c=a.flags;if(c&(f|k))this.dependencyDepth=r,l=a.evaluate===void 0?this.commitSignalValue(a,t):this.recomputeValue(a,t);else if(c&S){if(a.firstDep!==null){this.dependencyStack[r++]=t,e=a,t=a.firstDep;continue e}this.dependencyDepth=r,l=this.recomputeValue(a,t)}else l=!1}if(!l&&t.nextDep!==null){t=t.nextDep;continue}if(l){for(;r!==s;){this.dependencyDepth=--r;const a=this.dependencyStack[r];if(l=this.recomputeValue(e,a),e=a.sub,!l){if(a.nextDep!==null){t=a.nextDep;continue e}break}}if(l)return this.dependencyDepth=s,e.flags&b&&(e.flags&=~b),this.checkRoots[--this.checkingDepth]=null,!0}for(;r!==s;){if(e.flags&(f|b))continue e;this.dependencyDepth=--r;const a=this.dependencyStack[r];if(e.flags&=~(S|L),e=a.sub,a.nextDep!==null){t=a.nextDep;continue e}}if(e.flags&(f|b))continue e;return e.flags&=~(S|L),this.dependencyDepth=s,this.checkRoots[--this.checkingDepth]=null,!1}}catch(a){e.flags&b&&(e.flags&=~b);for(let c=s;c<r;c++)this.dependencyStack[c].sub.flags&=~L;this.checkRoots[--this.checkingDepth]=null,this.markRecoveryDependencies(i),this.restoreFailedDependency(i);for(let c=s;c<this.dependencyDepth;c++)this.restoreFailedDependency(this.dependencyStack[c].sub);throw this.dependencyDepth=s,this.dependencyStack.length=s,i.flags&o&&(i.flags&=~d),a}}restoreFailedDependency(e){if(e.evaluate===void 0){e.cachedValue=void 0,e.flags=0;return}e.flags&=-118800,e.flags&o||(e.flags|=k)}executeEffect(e){const t=e.flags;if(!(t&g)||!(t&(f|E))&&!this.refreshEffectBeforeRun(e))return;const i=e.evaluate;if(i===void 0){e.flags&=~g;return}if((e.scopeLastChild!==void 0||typeof e.cachedValue=="function")&&this.cleanupEffectBeforeRun(e),e.evaluate===void 0)return;e.tailDep=null,e.flags=e.flags&-1029|p;const s=this.activeSub;this.activeSub=e;let r;try{r=i()}catch(n){this.activeSub=s,e.flags&=~p,this.failEffectRun(e,n,void 0)}finally{this.activeSub=s,e.flags&=~p}const l=e.tailDep;(l===null?e.firstDep:l.nextDep)!==null&&this.pruneUnreadDependencies(e),typeof r=="function"&&(e.evaluate===void 0?this.untracked(r):e.cachedValue=r),e.flags&d?e.flags=e.flags&-1031|S:e.flags&=-1032}refreshEffectBeforeRun(e){const t=e.firstDep;return t===null||!this.walkDependencyChain(e,t)?(e.flags&=~g,!1):!0}cleanupEffectBeforeRun(e){let t;if(e.scopeLastChild!==void 0)try{this.disposeNestedEffects(e)}catch(s){t=[s]}const i=typeof e.cachedValue=="function"?e.cachedValue:void 0;if(e.cachedValue=void 0,e.flags&=~E,i!==void 0)try{this.untracked(i)}catch(s){t??=[],t.push(s)}if(t!==void 0){try{this.disposeEffect(e)}catch(s){t.push(s)}D.throwScopeErrors(t,"Effect cleanup failed.")}}failEffectRun(e,t,i){const s=i??[];s.push(t),this.pruneUnreadDependencies(e);try{this.disposeNestedEffects(e)}catch(r){s.push(r)}throw e.flags&=-72,s.length===1?s[0]:new AggregateError(s,"Effect execution failed.")}flushSyncEffects(){if(!(this.flushingEffects||this.activeSub!==null&&(this.activeSub.flags&(o|p))===(o|p))){this.flushingEffects=!0;try{for(;this.effectReadIndex!==this.effectWriteIndex;){const e=this.effectReadIndex,t=e===0?this.firstEffect:this.effectQueue[e];e===0?this.firstEffect=void 0:this.effectQueue[e]=void 0,++this.effectReadIndex,t.flags&=~d,this.executeEffect(t)}}catch(e){this.drainQueueAfterError(e,!1)}finally{this.effectReadIndex=0,this.effectWriteIndex=0,this.flushingEffects=!1}}}flushExternalEffects(){if(!(this.flushingEffects||this.activeSub!==null&&(this.activeSub.flags&(o|p))===(o|p))){this.flushingEffects=!0;try{for(;this.effectReadIndex!==this.effectWriteIndex;){const e=this.effectReadIndex,t=e===0?this.firstEffect:this.effectQueue[e];e===0?this.firstEffect=void 0:this.effectQueue[e]=void 0,++this.effectReadIndex;const i=t.effectTask;i===void 0?(t.flags&=~d,this.executeEffect(t)):t.evaluate!==void 0?this.scheduleEffectTask(t,i):t.flags&=~d}}catch(e){this.drainQueueAfterError(e,!0)}finally{this.effectReadIndex=0,this.effectWriteIndex=0,this.flushingEffects=!1}}}markRecoveryDependencies(e){const t=[e],i=new Set;for(;t.length!==0;){const s=t.pop();if(!i.has(s)){i.add(s);for(let r=s.firstDep;r!==null;r=r.nextDep){const l=r.dep;l.evaluate!==void 0&&!(l.flags&o)&&(l.flags|=_,t.push(l))}}}}drainQueueAfterError(e,t){const i=[e];for(;this.effectReadIndex!==this.effectWriteIndex;){const s=this.effectReadIndex++,r=s===0?this.firstEffect:this.effectQueue[s];s===0?this.firstEffect=void 0:this.effectQueue[s]=void 0;try{const l=t?r.effectTask:void 0;l!==void 0&&r.evaluate!==void 0?this.scheduleEffectTask(r,l):(r.flags&=~d,this.executeEffect(r))}catch(l){i.push(l)}}throw i.length===1?e:new AggregateError(i,"Effect queue processing failed.")}requestEffectTask(e){const t=e.effectTask;t===void 0||e.evaluate===void 0||(e.flags|=d,this.scheduleEffectTask(e,t))}scheduleEffectTask(e,t){try{t.schedule()}catch(i){this.failEffectSchedule(e,i)}}failEffectSchedule(e,t){try{e.flags&d&&this.settleCancelledDependencies(e)}catch(i){throw new AggregateError([t,i],"Effect scheduling and dependency settlement failed.")}finally{e.flags&=-72}throw t}disposeEffect(e){if(e.evaluate===void 0)return;this.activeSub===e&&(this.activeSub=null);const t=e.effectTask,i=e.onStop,s=typeof e.cachedValue=="function"?e.cachedValue:void 0;e.evaluate=void 0,e.flags=0,e.cachedValue=void 0,e.effectTask=void 0,i!==void 0&&(e.onStop=void 0),D.detachScopeChild(e);let r;e.tailDep=null;try{this.pruneUnreadDependencies(e)}catch(l){r=[l]}if(e.firstDep=e.tailDep=null,t!==void 0)try{t.dispose()}catch(l){r??=[],r.push(l)}try{this.disposeNestedEffects(e)}catch(l){r??=[],r.push(l)}if(s!==void 0)try{this.untracked(s)}catch(l){r??=[],r.push(l)}if(i!==void 0)try{this.untracked(i)}catch(l){r??=[],r.push(l)}this.invalidationStack.length!==this.invalidationDepth&&(this.invalidationStack.length=this.invalidationDepth),this.dependencyStack.length!==this.dependencyDepth&&(this.dependencyStack.length=this.dependencyDepth),r!==void 0&&D.throwScopeErrors(r,"Effect disposal failed.")}disposeNestedEffects(e){let t;for(;e.scopeLastChild!==void 0;)try{this.disposeEffect(e.scopeLastChild)}catch(i){t??=[],t.push(i)}t!==void 0&&D.throwScopeErrors(t,"Nested effect disposal failed.")}createHandleReaders(){const e=this;return{read(){return e.readComputedValue(this)},peek(){return e.peekHandle(this)}}}peekHandle(e){const t=this.activeSub;if(t===null)return e.get();this.activeSub=null;try{return e.get()}finally{this.activeSub=t}}_signalAccess(e){const t=this;let i=e,s;function r(l){if(arguments.length!==0){const c=s;c!==void 0?t.writeSignalValue(c,l):i!==l&&(i=l);return}const n=s;if(n!==void 0)return t.readSignalValue(n);const a=t.activeSub;return a===null||(s=t.materializeSignal(i,a)),i}return{read:r,write:r}}_computedAccess(e){return this.allocateGraphRecord(void 0,e,y,this.handleReaders.read)}_ownedSignal(e,t){const i=this;let s=e,r,l=!1;const n=()=>{const u=r;if(u!==void 0)return this.readSignalValue(u);const v=this.activeSub;if(v===null)return s;const C=s;return r=this.materializeSignal(C,v,t),s=void 0,C},a=t===void 0?u=>{const v=r;v!==void 0?this.writeSignalValue(v,u):s!==u&&(s=u)}:u=>{const v=r;if(v!==void 0){const C=v.flags&f?v.pendingValue:v.cachedValue;C!==u&&t.onChange?.(C,u,v.firstSub!==null),this.writeSignalValue(v,u);return}s!==u&&(t.onChange?.(s,u,!1),s=u)},V={source:{get:n,peek:this.handleReaders.peek,set:a},dispose(){if(l)return!0;l=!0,s=void 0;let u;try{t?.onDispose?.(r?.firstSub!=null)}catch(v){(u??=[]).push(v)}if(r!==void 0){try{i.releaseSourceSubs(r)}catch(v){(u??=[]).push(v)}r.cachedValue=void 0,r.pendingValue=void 0,r.pendingAuthor=void 0,r.flags=0}if(r=void 0,u?.length===1)throw u[0];if(u!==void 0&&u.length>1)throw new AggregateError(u,"Owned signal disposal failed.");return!0}};return t!==void 0&&(V.hasSubscribers=()=>r?.firstSub!=null),V}_ownedComputed(e,t){const i=this,s=this.createComputedHandle(e,t);let r=!1;const l={source:s,dispose(){if(r)return!0;r=!0,i.activeSub===s&&(i.activeSub=null);const n=[];try{t?.onDispose?.(s.firstSub!=null)}catch(c){n.push(c)}const a=!(s.flags&y);if(a)try{i.releaseSourceSubs(s)}catch(c){n.push(c)}if(s.evaluate=void 0,s.cachedValue=void 0,s.flags=0,s.tailDep=null,a)try{i.pruneUnreadDependencies(s)}catch(c){n.push(c)}if(s.firstDep=s.tailDep=null,n.length===1)throw n[0];if(n.length>1)throw new AggregateError(n,"Owned computed disposal failed.");return!0}};return t!==void 0&&(l.hasSubscribers=()=>s.firstSub!=null),l}_startBatch(){++this.batchDepth}_endBatch(){!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}_isTracking(){return this.activeSub!==null}_probeReads(e){const t=this.probeDepth===0?this.probeNode??=this.allocateGraphRecord(void 0,U,0,void 0):this.allocateGraphRecord(void 0,U,0,void 0),i=this.activeSub;this.activeSub=t,this.probeDepth++;let s=!1;try{e()}finally{this.probeDepth--,this.activeSub=i,t.firstDep!==null&&(s=!0,t.tailDep=null,this.pruneUnreadDependencies(t))}return s}_isBatching(){return this.batchDepth!==0}_isFlushingEffects(){return this.flushingEffects}_allocateTaskEffect(e,t){const i=this.allocateGraphRecord(void 0,e,f|S|o,void 0),s=this.activeSub;return s!==null&&s.flags&o&&D.appendScopeChild(s,i),i.effectTask=t,i}_requestTaskEffect(e,t){t?this.requestEffectTask(e):e.effectTask!==void 0&&e.evaluate!==void 0&&(e.flags|=d),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}_failTaskEffectSchedule(e,t){return this.failEffectSchedule(e,t)}_beginTaskEffectRun(e){return!(e.flags&d)||e.evaluate===void 0?!1:(e.flags&=~d,!0)}_finishTaskEffectRun(e){const t=this.activeSub;this.activeSub=null;try{try{this.executeEffect(e)}catch(i){if(!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(s){throw new AggregateError([i,s],"Effect execution and queue processing failed.")}throw i}!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}finally{this.activeSub=t}}_cancelTaskEffect(e){return e.evaluate===void 0?!1:(this.settleCancelledDependencies(e),e.flags&=-72,!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),!0)}_rearmTaskEffect(e){const t=e.effectTask;t===void 0||e.evaluate===void 0||(e.flags|=f|d,t.schedule())}_disposeTaskEffect(e){this.disposeEffect(e)}_trackSignalNode(e,t){const i=this.activeSub;if(i!==null)return this.materializeSignal(e,i,t)}_readSignalNode(e){return this.readSignalValue(e)}_peekSignalNode(e){const t=this.activeSub;if(t===null)return this.readSignalValue(e);this.activeSub=null;try{return this.readSignalValue(e)}finally{this.activeSub=t}}_visibleSignalValue(e){return e.flags&f?e.pendingValue:e.cachedValue}_writeSignalNode(e,t){this.writeSignalValue(e,t)}_signalNodeHasSubscribers(e){return e.firstSub!==null}_releaseSignalNode(e){try{this.releaseSourceSubs(e)}finally{e.cachedValue=void 0,e.pendingValue!==void 0&&(e.pendingValue=void 0),e.pendingAuthor!=null&&(e.pendingAuthor=void 0),e.flags=0}}_findSubscriberOwner(e,t,i){for(let s=e.firstSub;s!==null;s=s.nextSub){const r=s.sub,l=r.sourceHooks?.dependencyOwner??r.effectTask?.dependencyOwner;if(l!==void 0&&t(l,i))return l}}_activeSubscriberOwner(){const e=this.activeSub;if(e!==null)return e.sourceHooks?.dependencyOwner??e.effectTask?.dependencyOwner}_bumpSignalNode(e){return e.firstSub===null?!1:(this.writeSignalValue(e,(e.flags&f?e.pendingValue:e.cachedValue)+1),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),!0)}_trackCounterNode(e){const t=this.activeSub;if(t===null)return;const i={flags:h,firstSub:null,lastSub:null,evaluate:void 0,cachedValue:0,sourceHooks:e};return t.flags&I?this.appendInitialDependency(i,t):this.trackDependency(i,t),i}_activeEffectTask(){const e=this.activeSub;return e===null?void 0:e.effectTask}}function U(){}exports.ScopeNode=D.ScopeNode;exports.ReactivityEngine=H;
|