@askrjs/askr 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +874 -0
- package/README.md +61 -29
- package/capabilities.json +19 -9
- package/dist/actions/index.js +56 -12
- package/dist/benchmark.js +10 -15
- package/dist/boot/index.d.ts +3 -2
- package/dist/boot/index.js +1 -1
- package/dist/boot-DaoTYoCw.js +3989 -0
- package/dist/browser-activity-CB8e-V4f.js +220 -0
- package/dist/components/index.d.ts +8 -1
- package/dist/components/index.js +1 -43
- package/dist/{aria-hKjThHcp.js → compose-ref-DWzdbxsD.js} +41 -4
- package/dist/control/index.d.ts +2 -0
- package/dist/control/index.js +1 -1
- package/dist/control-nfpT2fbK.js +209 -0
- package/dist/core.d.ts +5 -9
- package/dist/csp-nonce-DwGw1A6Q.js +35 -0
- package/dist/data/index.js +3 -3
- package/dist/{data-2edW0jhF.js → data-BCwClJiF.js} +283 -94
- package/dist/data-runtime-C1bFAlba.js +242 -0
- package/dist/{deferred-CbgNhf67.js → deferred-bEEHHvic.js} +42 -20
- package/dist/domains/actions.d.ts +8 -3
- package/dist/domains/component.d.ts +1 -107
- package/dist/domains/context.d.ts +0 -15
- package/dist/domains/control.d.ts +36 -249
- package/dist/domains/data.d.ts +31 -13
- package/dist/domains/diagnostics.d.ts +1 -2
- package/dist/domains/lifecycle.d.ts +2 -5
- package/dist/domains/refs.d.ts +0 -2
- package/dist/domains/routing.d.ts +43 -8
- package/dist/domains/scheduler.d.ts +1 -76
- package/dist/domains/server.d.ts +5 -2
- package/dist/domains/state.d.ts +2 -5
- package/dist/domains/telemetry.d.ts +0 -2
- package/dist/elements.d.ts +214 -51
- package/dist/error-boundary-Bpwofwps.js +293 -0
- package/dist/foundations/icon/index.d.ts +0 -58
- package/dist/foundations/icon/index.js +2 -2
- package/dist/foundations/index.js +2 -1
- package/dist/foundations/interactions/index.js +1 -1
- package/dist/foundations/state/index.d.ts +3 -3
- package/dist/foundations/state/index.js +5 -3
- package/dist/foundations/structures/index.js +2 -1
- package/dist/foundations/utilities/index.d.ts +2 -0
- package/dist/foundations/utilities/index.js +1 -2
- package/dist/fx/index.d.ts +31 -58
- package/dist/fx/index.js +313 -195
- package/dist/hooks-BimKStr4.js +202 -0
- package/dist/index.d.ts +11 -74
- package/dist/index.js +8 -447
- package/dist/instance-BAnfmXOR.js +988 -0
- package/dist/{interactions-CTeACdT_.js → interactions-D2BoREb-.js} +3 -2
- package/dist/jsx-dev-runtime.d.ts +41 -18
- package/dist/jsx-dev-runtime.js +1 -6
- package/dist/{jsx-runtime-CPJXAOBF.js → jsx-runtime-C4idqHY0.js} +18 -7
- package/dist/jsx-runtime.js +1 -1
- package/dist/jsx.d.ts +61 -37
- package/dist/{manifest-D1P3UNWV.js → manifest-CW9gyNBY.js} +3 -3
- package/dist/{navigate-prC5V8XV.js → navigate-CP_0Zy5U.js} +454 -87
- package/dist/navigation.d.ts +12 -3
- package/dist/peer-types.d.ts +8 -0
- package/dist/portal-DuOKfnLa.js +349 -0
- package/dist/promise-Dz8iIHAm.js +16 -0
- package/dist/query-registry-WMCN0BJL.js +320 -0
- package/dist/readable-DFWOsTac.js +21 -0
- package/dist/{render-context-B7ohlh6t.js → render-context-DGHnEveC.js} +27 -11
- package/dist/render-sync-IC5lMFpq.js +1240 -0
- package/dist/resolution-Cx82-xjW.js +1244 -0
- package/dist/resource-CLjB7RBQ.js +377 -0
- package/dist/resources/index.d.ts +21 -11
- package/dist/resources/index.js +45 -244
- package/dist/router/index.d.ts +14 -5
- package/dist/router/index.js +22 -53
- package/dist/scope-CwpVSHVf.js +55 -0
- package/dist/{shared-kU8yvryp.js → shared-O2ZnmYAf.js} +1 -7
- package/dist/{snapshot-source-An4iKajG.js → snapshot-Cjx4N988.js} +6 -1
- package/dist/ssg/index.d.ts +1 -2
- package/dist/ssg/index.js +5 -13
- package/dist/ssr/index.d.ts +26 -28
- package/dist/ssr/index.js +4 -4
- package/dist/{ssr-CiNm6Vzl.js → ssr-BJ8ug7zH.js} +133 -122
- package/dist/ssr-DoV-vJ-5.js +229 -0
- package/dist/state-DWO1KzkX.js +232 -0
- package/dist/structures-D4dDMqHX.js +231 -0
- package/dist/testing/index.d.ts +8 -4
- package/dist/testing/index.js +29 -34
- package/dist/url-CnbfpX0K.js +185 -0
- package/dist/utilities.d.ts +48 -2
- package/dist/verify-hydration-DpVaDnqz.js +152 -0
- package/package.json +19 -9
- package/dist/access-CEA2pOry.js +0 -1046
- package/dist/activity-oy2YFTFF.js +0 -201
- package/dist/boot-BMBMWUGI.js +0 -1084
- package/dist/capabilities-Bbf0mlp9.js +0 -42
- package/dist/compose-ref-v0qGlHoN.js +0 -26
- package/dist/control-BR_mrX__.js +0 -173
- package/dist/control-C-ApnFs1.js +0 -20
- package/dist/csp-nonce-BfFWcd0w.js +0 -173
- package/dist/data-runtime-CxoY98lX.js +0 -149
- package/dist/default-portal-runtime-DvMvWJVp.js +0 -20
- package/dist/dom-renderer.d.ts +0 -77
- package/dist/domains/renderer.d.ts +0 -127
- package/dist/eager-control.d.ts +0 -8
- package/dist/effect-C3Zsc1k6.js +0 -292
- package/dist/for-state-BDykeOJL.js +0 -1753
- package/dist/instance-VAFYVJOa.js +0 -1027
- package/dist/notify-DxxuDPeY.js +0 -266
- package/dist/portal-w3oQ6oQU.js +0 -29
- package/dist/query-registry-LrYpQsDJ.js +0 -83
- package/dist/render-resolved-BC0W7_5b.js +0 -1123
- package/dist/renderer-CT0HeY58.js +0 -8623
- package/dist/resolution-3DskUkjG.js +0 -577
- package/dist/resource-18-sFRl9.js +0 -344
- package/dist/route-matching-CUzZ31gT.js +0 -551
- package/dist/router-internal-7nuNEHfG.js +0 -36
- package/dist/scope-Cq_iYbTR.js +0 -403
- package/dist/selector-BSPVkjKP.js +0 -311
- package/dist/ssr-EPjwJH5R.js +0 -29
- package/dist/state-BXJfudq1.js +0 -91
- package/dist/structures-CjEzfj4h.js +0 -654
- package/dist/timer-C7uqnJVt.js +0 -85
- package/dist/verify-hydration-ikaxotf7.js +0 -27
- package/dist/vnode-D24p6IW2.js +0 -7
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { JSXElementType, JSXElement, Props } from '../elements.js';
|
|
2
|
-
import '../jsx-globals.js';
|
|
3
|
-
import { AuthContext, AuthRequirement } from '@askrjs/auth';
|
|
4
|
-
import { InferSchema, ObjectSchema } from '@askrjs/schema';
|
|
5
|
-
import { VNode, ContextFrame } from './context.js';
|
|
6
|
-
import { ComponentInstance, ReadableSource } from './component.js';
|
|
7
|
-
import { Scheduler } from './scheduler.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Internal DOM range shape shared by runtime ownership records and the
|
|
11
|
-
* renderer. A singleton range uses the node itself for both anchors; a
|
|
12
|
-
* multi-node or empty range uses deterministic comment anchors.
|
|
13
|
-
*/
|
|
14
|
-
interface DOMRange {
|
|
15
|
-
start: Node;
|
|
16
|
-
end: Node;
|
|
17
|
-
single: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface ChildScope {
|
|
21
|
-
key: string | number;
|
|
22
|
-
componentInstance: ComponentInstance;
|
|
23
|
-
previousVnode: VNode | undefined;
|
|
24
|
-
vnode: VNode | undefined;
|
|
25
|
-
dom?: Node;
|
|
26
|
-
/** @internal Fast singleton node plus an anchor-backed multi-node range. */
|
|
27
|
-
range?: DOMRange;
|
|
28
|
-
needsDomUpdate: boolean;
|
|
29
|
-
hydrationPending: boolean;
|
|
30
|
-
/** @internal Stable owner for validated intrinsic blueprints in list items. */
|
|
31
|
-
blueprintOwner?: object;
|
|
32
|
-
render(renderFn: () => VNode): VNode;
|
|
33
|
-
markDirty(): void;
|
|
34
|
-
dispose(): void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ChildScopeOwnership {
|
|
38
|
-
add(scope: ChildScope): void;
|
|
39
|
-
delete(scope: ChildScope): void;
|
|
40
|
-
bulkDispose(run: () => void): void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** @internal Snapshot used to restore a child scope after a failed commit. */
|
|
44
|
-
interface ChildScopeTransactionSnapshot {
|
|
45
|
-
previousVnode: VNode | undefined;
|
|
46
|
-
vnode: VNode | undefined;
|
|
47
|
-
dom: Node | undefined;
|
|
48
|
-
range: DOMRange | undefined;
|
|
49
|
-
domTextData: string | undefined;
|
|
50
|
-
needsDomUpdate: boolean;
|
|
51
|
-
hydrationPending: boolean;
|
|
52
|
-
renderFn: (() => VNode) | undefined;
|
|
53
|
-
renderedOwnerFrame: ContextFrame | null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Diagnostic breakdown of a keyed-list reorder decision, returned by {@link RuntimeRendererHost.isKeyedReorderFastPathEligible}. */
|
|
57
|
-
interface RuntimeKeyedReorderDecision {
|
|
58
|
-
useFastPath: boolean;
|
|
59
|
-
totalKeyed: number;
|
|
60
|
-
totalChildren: number;
|
|
61
|
-
currentKeyCount: number;
|
|
62
|
-
moveCount: number;
|
|
63
|
-
lisLen: number;
|
|
64
|
-
hasPropChanges: boolean;
|
|
65
|
-
isWholeKeyedList: boolean;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** The renderer implementation an {@link AskrRuntime} delegates DOM evaluation and cleanup to. */
|
|
69
|
-
interface RuntimeRendererHost {
|
|
70
|
-
evaluate(
|
|
71
|
-
node: unknown,
|
|
72
|
-
target: Element | null,
|
|
73
|
-
context?: object,
|
|
74
|
-
retainedOwner?: ComponentInstance
|
|
75
|
-
): void;
|
|
76
|
-
cleanupInstancesUnder(node: Node): void;
|
|
77
|
-
replaceComponentRange(
|
|
78
|
-
instance: ComponentInstance,
|
|
79
|
-
result: unknown,
|
|
80
|
-
host: Element | Comment
|
|
81
|
-
): Node | null;
|
|
82
|
-
resolveChildScopeRange?(scope: ChildScope): DOMRange | null;
|
|
83
|
-
teardownNodeSubtree(root: Node): void;
|
|
84
|
-
populateKeyMapForElement(parent: Element): void;
|
|
85
|
-
getKeyMapForElement(
|
|
86
|
-
parent: Element
|
|
87
|
-
): Map<string | number, Element> | undefined;
|
|
88
|
-
isKeyedReorderFastPathEligible(
|
|
89
|
-
parent: Element,
|
|
90
|
-
children: unknown[],
|
|
91
|
-
oldKeyMap: Map<string | number, Element> | undefined
|
|
92
|
-
): RuntimeKeyedReorderDecision;
|
|
93
|
-
markReactivePropsDirtySource(source: ReadableSource<unknown>): void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Options for {@link createRuntime}. */
|
|
97
|
-
interface AskrRuntimeOptions {
|
|
98
|
-
scheduler?: Scheduler;
|
|
99
|
-
renderer?: RuntimeRendererHost;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Construction-only scheduler and renderer wiring. Mounting uses the default runtime. */
|
|
103
|
-
declare class AskrRuntime {
|
|
104
|
-
readonly scheduler: Scheduler;
|
|
105
|
-
private rendererHost;
|
|
106
|
-
constructor(options?: AskrRuntimeOptions);
|
|
107
|
-
get renderer(): RuntimeRendererHost;
|
|
108
|
-
configureRenderer(renderer: RuntimeRendererHost): void;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Create construction-only runtime wiring. Omitted schedulers share the default scheduler; mounting uses the default runtime. */
|
|
112
|
-
declare function createRuntime(options?: AskrRuntimeOptions): AskrRuntime;
|
|
113
|
-
|
|
114
|
-
/** Get the process-wide default {@link AskrRuntime}. */
|
|
115
|
-
declare function getDefaultRuntime(): AskrRuntime;
|
|
116
|
-
export {
|
|
117
|
-
DOMRange,
|
|
118
|
-
ChildScope,
|
|
119
|
-
ChildScopeOwnership,
|
|
120
|
-
ChildScopeTransactionSnapshot,
|
|
121
|
-
RuntimeKeyedReorderDecision,
|
|
122
|
-
RuntimeRendererHost,
|
|
123
|
-
AskrRuntimeOptions,
|
|
124
|
-
AskrRuntime,
|
|
125
|
-
createRuntime,
|
|
126
|
-
getDefaultRuntime,
|
|
127
|
-
};
|
package/dist/eager-control.d.ts
DELETED
package/dist/effect-C3Zsc1k6.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { b as ScheduledWork, f as requestRuntimeWork, y as SCHEDULER_LANES } from "./access-CEA2pOry.js";
|
|
2
|
-
import { S as withFineGrainedReadTracking } from "./notify-DxxuDPeY.js";
|
|
3
|
-
//#region src/runtime/reactivity/effect.ts
|
|
4
|
-
const SOURCE_EFFECTS = Symbol("askr.source-effects");
|
|
5
|
-
const effectSources = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
const dirtyEffectsByLane = {
|
|
7
|
-
derived: /* @__PURE__ */ new Set(),
|
|
8
|
-
component: /* @__PURE__ */ new Set(),
|
|
9
|
-
reactive: /* @__PURE__ */ new Set(),
|
|
10
|
-
post: /* @__PURE__ */ new Set()
|
|
11
|
-
};
|
|
12
|
-
const MAX_EFFECT_RUNS_PER_FLUSH = 50;
|
|
13
|
-
const LANE_FLUSH_TASKS = {
|
|
14
|
-
derived: new ScheduledWork(() => flushLaneEffects("derived")),
|
|
15
|
-
component: new ScheduledWork(() => flushLaneEffects("component")),
|
|
16
|
-
reactive: new ScheduledWork(() => flushLaneEffects("reactive")),
|
|
17
|
-
post: new ScheduledWork(() => flushLaneEffects("post"))
|
|
18
|
-
};
|
|
19
|
-
function isEffectReadSourceCollection(sources) {
|
|
20
|
-
return Array.isArray(sources) || sources instanceof Set;
|
|
21
|
-
}
|
|
22
|
-
function effectReadSourceCollectionHas(sources, source) {
|
|
23
|
-
return Array.isArray(sources) ? sources.includes(source) : sources.has(source);
|
|
24
|
-
}
|
|
25
|
-
function getRegisteredEffects(source) {
|
|
26
|
-
return source[SOURCE_EFFECTS] ?? effectSources.get(source);
|
|
27
|
-
}
|
|
28
|
-
function setRegisteredEffects(source, registered) {
|
|
29
|
-
const effectSource = source;
|
|
30
|
-
try {
|
|
31
|
-
effectSource[SOURCE_EFFECTS] = registered;
|
|
32
|
-
if (effectSource[SOURCE_EFFECTS] === registered) return;
|
|
33
|
-
} catch {}
|
|
34
|
-
effectSources.set(source, registered);
|
|
35
|
-
}
|
|
36
|
-
function deleteRegisteredEffects(source) {
|
|
37
|
-
const effectSource = source;
|
|
38
|
-
if (effectSource[SOURCE_EFFECTS] !== void 0) try {
|
|
39
|
-
delete effectSource[SOURCE_EFFECTS];
|
|
40
|
-
return;
|
|
41
|
-
} catch {}
|
|
42
|
-
effectSources.delete(source);
|
|
43
|
-
}
|
|
44
|
-
function registerEffectSource(source, effect) {
|
|
45
|
-
const registered = getRegisteredEffects(source);
|
|
46
|
-
if (!registered) {
|
|
47
|
-
setRegisteredEffects(source, effect);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (registered instanceof Set) {
|
|
51
|
-
registered.add(effect);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (registered === effect) return;
|
|
55
|
-
setRegisteredEffects(source, /* @__PURE__ */ new Set([registered, effect]));
|
|
56
|
-
}
|
|
57
|
-
function unregisterEffectSource(source, effect) {
|
|
58
|
-
const registered = getRegisteredEffects(source);
|
|
59
|
-
if (!registered) return;
|
|
60
|
-
if (!(registered instanceof Set)) {
|
|
61
|
-
if (registered === effect) deleteRegisteredEffects(source);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
registered.delete(effect);
|
|
65
|
-
if (registered.size === 0) deleteRegisteredEffects(source);
|
|
66
|
-
else if (registered.size === 1) setRegisteredEffects(source, registered.values().next().value);
|
|
67
|
-
}
|
|
68
|
-
function clearEffectSubscriptions(effect) {
|
|
69
|
-
const sources = effect.readSources;
|
|
70
|
-
if (isEffectReadSourceCollection(sources)) {
|
|
71
|
-
for (const source of sources) unregisterEffectSource(source, effect);
|
|
72
|
-
if (sources instanceof Set) sources.clear();
|
|
73
|
-
else sources.length = 0;
|
|
74
|
-
} else if (sources) unregisterEffectSource(sources, effect);
|
|
75
|
-
if (effect.readSource2) unregisterEffectSource(effect.readSource2, effect);
|
|
76
|
-
effect.readSources = null;
|
|
77
|
-
effect.readSource2 = null;
|
|
78
|
-
}
|
|
79
|
-
function evaluateAndCommitEffect(effect) {
|
|
80
|
-
effect._pendingFineGrainedReadSource = null;
|
|
81
|
-
effect._pendingFineGrainedReadSources = null;
|
|
82
|
-
try {
|
|
83
|
-
let value;
|
|
84
|
-
try {
|
|
85
|
-
value = withFineGrainedReadTracking(effect, effect.compute);
|
|
86
|
-
} catch (error) {
|
|
87
|
-
if (!effect.hasValue) {
|
|
88
|
-
const [nextSources, nextSource2] = getPendingEffectSources(effect);
|
|
89
|
-
commitEffectSubscriptions(effect, nextSources, nextSource2);
|
|
90
|
-
}
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
const [nextSources, nextSource2] = getPendingEffectSources(effect);
|
|
94
|
-
commitEffectResult(effect, value, nextSources, nextSource2);
|
|
95
|
-
} finally {
|
|
96
|
-
effect._pendingFineGrainedReadSource = null;
|
|
97
|
-
effect._pendingFineGrainedReadSources = null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function getPendingEffectSources(effect) {
|
|
101
|
-
const pendingAdditionalSources = effect._pendingFineGrainedReadSources;
|
|
102
|
-
const hasPendingCollection = isEffectReadSourceCollection(pendingAdditionalSources);
|
|
103
|
-
return [hasPendingCollection ? pendingAdditionalSources : effect._pendingFineGrainedReadSource, pendingAdditionalSources && !hasPendingCollection ? pendingAdditionalSources : null];
|
|
104
|
-
}
|
|
105
|
-
function commitEffectSubscriptions(effect, nextSources, nextSource2) {
|
|
106
|
-
const previousSources = effect.readSources;
|
|
107
|
-
const previousSource2 = effect.readSource2;
|
|
108
|
-
if (previousSources === nextSources && previousSource2 === nextSource2) return;
|
|
109
|
-
const previousCollection = isEffectReadSourceCollection(previousSources);
|
|
110
|
-
const nextCollection = isEffectReadSourceCollection(nextSources);
|
|
111
|
-
if (!previousCollection && !nextCollection) {
|
|
112
|
-
if (previousSources && previousSources !== nextSources && previousSources !== nextSource2) unregisterEffectSource(previousSources, effect);
|
|
113
|
-
if (previousSource2 && previousSource2 !== nextSources && previousSource2 !== nextSource2) unregisterEffectSource(previousSource2, effect);
|
|
114
|
-
if (nextSources && nextSources !== previousSources && nextSources !== previousSource2) registerEffectSource(nextSources, effect);
|
|
115
|
-
if (nextSource2 && nextSource2 !== previousSources && nextSource2 !== previousSource2) registerEffectSource(nextSource2, effect);
|
|
116
|
-
effect.readSources = nextSources;
|
|
117
|
-
effect.readSource2 = nextSource2;
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const stateHas = (sources, source2, source) => isEffectReadSourceCollection(sources) ? effectReadSourceCollectionHas(sources, source) : sources === source || source2 === source;
|
|
121
|
-
if ((previousCollection ? Array.isArray(previousSources) ? previousSources.length : previousSources.size : (previousSources ? 1 : 0) + (previousSource2 ? 1 : 0)) === (nextCollection ? Array.isArray(nextSources) ? nextSources.length : nextSources.size : (nextSources ? 1 : 0) + (nextSource2 ? 1 : 0))) {
|
|
122
|
-
let same = true;
|
|
123
|
-
if (previousCollection) {
|
|
124
|
-
for (const source of previousSources) if (!stateHas(nextSources, nextSource2, source)) {
|
|
125
|
-
same = false;
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
} else same = (!previousSources || stateHas(nextSources, nextSource2, previousSources)) && (!previousSource2 || stateHas(nextSources, nextSource2, previousSource2));
|
|
129
|
-
if (same) return;
|
|
130
|
-
}
|
|
131
|
-
if (previousCollection) {
|
|
132
|
-
for (const source of previousSources) if (!stateHas(nextSources, nextSource2, source)) unregisterEffectSource(source, effect);
|
|
133
|
-
} else {
|
|
134
|
-
if (previousSources && !stateHas(nextSources, nextSource2, previousSources)) unregisterEffectSource(previousSources, effect);
|
|
135
|
-
if (previousSource2 && !stateHas(nextSources, nextSource2, previousSource2)) unregisterEffectSource(previousSource2, effect);
|
|
136
|
-
}
|
|
137
|
-
if (nextCollection) {
|
|
138
|
-
for (const source of nextSources) if (!stateHas(previousSources, previousSource2, source)) registerEffectSource(source, effect);
|
|
139
|
-
} else {
|
|
140
|
-
if (nextSources && !stateHas(previousSources, previousSource2, nextSources)) registerEffectSource(nextSources, effect);
|
|
141
|
-
if (nextSource2 && !stateHas(previousSources, previousSource2, nextSource2)) registerEffectSource(nextSource2, effect);
|
|
142
|
-
}
|
|
143
|
-
effect.readSources = nextSources;
|
|
144
|
-
effect.readSource2 = nextSource2;
|
|
145
|
-
}
|
|
146
|
-
function commitEffectResult(effect, value, nextSources, nextSource2) {
|
|
147
|
-
const previousValue = effect.lastValue;
|
|
148
|
-
const shouldCommit = !effect.hasValue || !effect.equals(previousValue, value);
|
|
149
|
-
commitEffectSubscriptions(effect, nextSources, nextSource2);
|
|
150
|
-
if (shouldCommit) effect.commit(value, effect.hasValue ? previousValue : void 0);
|
|
151
|
-
effect.lastValue = value;
|
|
152
|
-
effect.hasValue = true;
|
|
153
|
-
}
|
|
154
|
-
function handleEffectError(effect, error) {
|
|
155
|
-
if (effect.onError) {
|
|
156
|
-
effect.onError(error);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
function flushLaneEffects(lane) {
|
|
162
|
-
const effects = dirtyEffectsByLane[lane];
|
|
163
|
-
if (effects.size === 0) return;
|
|
164
|
-
const pending = effects.values();
|
|
165
|
-
const effectRuns = /* @__PURE__ */ new Map();
|
|
166
|
-
let failures = null;
|
|
167
|
-
let next = pending.next();
|
|
168
|
-
while (!next.done) {
|
|
169
|
-
const effect = next.value;
|
|
170
|
-
effects.delete(effect);
|
|
171
|
-
if (!effect.isActive) {
|
|
172
|
-
next = pending.next();
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
const runCount = (effectRuns.get(effect) ?? 0) + 1;
|
|
176
|
-
effectRuns.set(effect, runCount);
|
|
177
|
-
if (runCount > MAX_EFFECT_RUNS_PER_FLUSH) {
|
|
178
|
-
const error = /* @__PURE__ */ new Error(`[Askr] fine-grained effect exceeded ${MAX_EFFECT_RUNS_PER_FLUSH} runs in one flush. Likely reactive cycle.`);
|
|
179
|
-
try {
|
|
180
|
-
handleEffectError(effect, error);
|
|
181
|
-
} catch (unhandledError) {
|
|
182
|
-
(failures ??= []).push(unhandledError);
|
|
183
|
-
}
|
|
184
|
-
next = pending.next();
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
try {
|
|
188
|
-
evaluateAndCommitEffect(effect);
|
|
189
|
-
} catch (error) {
|
|
190
|
-
try {
|
|
191
|
-
handleEffectError(effect, error);
|
|
192
|
-
} catch (unhandledError) {
|
|
193
|
-
(failures ??= []).push(unhandledError);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
next = pending.next();
|
|
197
|
-
}
|
|
198
|
-
if (failures?.length === 1) throw failures[0];
|
|
199
|
-
if (failures && failures.length > 1) throw new AggregateError(failures, "Fine-grained effect failures");
|
|
200
|
-
}
|
|
201
|
-
function unscheduleEffect(effect) {
|
|
202
|
-
dirtyEffectsByLane[effect.lane].delete(effect);
|
|
203
|
-
}
|
|
204
|
-
function recomputeEffectNow(effect) {
|
|
205
|
-
try {
|
|
206
|
-
evaluateAndCommitEffect(effect);
|
|
207
|
-
} catch (error) {
|
|
208
|
-
handleEffectError(effect, error);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function markFineGrainedEffectsDirtySource(source) {
|
|
212
|
-
const registered = getRegisteredEffects(source);
|
|
213
|
-
if (!registered) return;
|
|
214
|
-
if (registered instanceof Set) for (const effect of registered) markDirtyEffect(effect);
|
|
215
|
-
else markDirtyEffect(registered);
|
|
216
|
-
for (const lane of SCHEDULER_LANES) if (dirtyEffectsByLane[lane].size) requestRuntimeWork(lane, LANE_FLUSH_TASKS[lane]);
|
|
217
|
-
}
|
|
218
|
-
function markDirtyEffect(effect) {
|
|
219
|
-
if (!effect.isActive) return;
|
|
220
|
-
dirtyEffectsByLane[effect.lane].add(effect);
|
|
221
|
-
}
|
|
222
|
-
var FineGrainedEffectImpl = class {
|
|
223
|
-
constructor(lane, compute, commit, equals, onError, owner) {
|
|
224
|
-
this.readSources = null;
|
|
225
|
-
this.readSource2 = null;
|
|
226
|
-
this._pendingFineGrainedReadSource = null;
|
|
227
|
-
this._pendingFineGrainedReadSources = null;
|
|
228
|
-
this.isActive = true;
|
|
229
|
-
this.hasValue = false;
|
|
230
|
-
this.lastValue = void 0;
|
|
231
|
-
this._owner = owner;
|
|
232
|
-
this.lane = lane;
|
|
233
|
-
this.compute = compute;
|
|
234
|
-
this.commit = commit;
|
|
235
|
-
this.equals = equals;
|
|
236
|
-
this.onError = onError;
|
|
237
|
-
}
|
|
238
|
-
cleanup() {
|
|
239
|
-
if (!this.isActive) return;
|
|
240
|
-
this.isActive = false;
|
|
241
|
-
unscheduleEffect(this);
|
|
242
|
-
clearEffectSubscriptions(this);
|
|
243
|
-
}
|
|
244
|
-
updateCompute(nextCompute) {
|
|
245
|
-
if (!this.isActive) return;
|
|
246
|
-
const previousCompute = this.compute;
|
|
247
|
-
const previousReadSources = this.readSources;
|
|
248
|
-
const previousReadSource2 = this.readSource2;
|
|
249
|
-
const previousHasValue = this.hasValue;
|
|
250
|
-
const previousLastValue = this.lastValue;
|
|
251
|
-
this.compute = nextCompute;
|
|
252
|
-
unscheduleEffect(this);
|
|
253
|
-
try {
|
|
254
|
-
recomputeEffectNow(this);
|
|
255
|
-
} catch (error) {
|
|
256
|
-
this.compute = previousCompute;
|
|
257
|
-
unscheduleEffect(this);
|
|
258
|
-
commitEffectSubscriptions(this, previousReadSources, previousReadSource2);
|
|
259
|
-
this.hasValue = previousHasValue;
|
|
260
|
-
this.lastValue = previousLastValue;
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
flush() {
|
|
265
|
-
if (!this.isActive) return;
|
|
266
|
-
unscheduleEffect(this);
|
|
267
|
-
recomputeEffectNow(this);
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
function createFineGrainedEffect(options) {
|
|
271
|
-
const effect = new FineGrainedEffectImpl(options.lane, options.compute, options.commit, options.equals ?? Object.is, options.onError, options._owner);
|
|
272
|
-
try {
|
|
273
|
-
recomputeEffectNow(effect);
|
|
274
|
-
} catch (error) {
|
|
275
|
-
effect.cleanup();
|
|
276
|
-
throw error;
|
|
277
|
-
}
|
|
278
|
-
return effect;
|
|
279
|
-
}
|
|
280
|
-
/** @internal Allocation-sensitive variant for shared renderer callbacks. */
|
|
281
|
-
function createOwnedFineGrainedEffect(lane, compute, commit, equals, onError, owner) {
|
|
282
|
-
const effect = new FineGrainedEffectImpl(lane, compute, commit, equals, onError, owner);
|
|
283
|
-
try {
|
|
284
|
-
recomputeEffectNow(effect);
|
|
285
|
-
} catch (error) {
|
|
286
|
-
effect.cleanup();
|
|
287
|
-
throw error;
|
|
288
|
-
}
|
|
289
|
-
return effect;
|
|
290
|
-
}
|
|
291
|
-
//#endregion
|
|
292
|
-
export { createOwnedFineGrainedEffect as n, markFineGrainedEffectsDirtySource as r, createFineGrainedEffect as t };
|