@askrjs/askr 0.0.47 → 0.0.49
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/dist/benchmark.js +6 -6
- package/dist/benchmark.js.map +1 -1
- package/dist/boot/hydration.js +140 -0
- package/dist/boot/hydration.js.map +1 -0
- package/dist/boot/index.d.ts +3 -56
- package/dist/boot/index.d.ts.map +1 -1
- package/dist/boot/index.js +62 -410
- package/dist/boot/index.js.map +1 -1
- package/dist/boot/root-lifecycle.d.ts +15 -0
- package/dist/boot/root-lifecycle.d.ts.map +1 -0
- package/dist/boot/root-lifecycle.js +205 -0
- package/dist/boot/root-lifecycle.js.map +1 -0
- package/dist/boot/route-startup.js +45 -0
- package/dist/boot/route-startup.js.map +1 -0
- package/dist/boot/types.d.ts +62 -0
- package/dist/boot/types.d.ts.map +1 -0
- package/dist/common/component.d.ts +3 -1
- package/dist/common/component.d.ts.map +1 -1
- package/dist/common/jsx.d.ts +1 -1
- package/dist/common/jsx.d.ts.map +1 -1
- package/dist/common/jsx.js.map +1 -1
- package/dist/common/props.d.ts +1 -1
- package/dist/common/render-context.js +55 -0
- package/dist/common/render-context.js.map +1 -0
- package/dist/common/router.d.ts +5 -1
- package/dist/common/router.d.ts.map +1 -1
- package/dist/common/ssr.d.ts +1 -1
- package/dist/common/ssr.js.map +1 -1
- package/dist/common/vnode.d.ts +5 -4
- package/dist/common/vnode.d.ts.map +1 -1
- package/dist/common/vnode.js.map +1 -1
- package/dist/components/error-boundary.d.ts +1 -1
- package/dist/components/error-boundary.js +2 -1
- package/dist/components/error-boundary.js.map +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/control/for.js +2 -1
- package/dist/control/for.js.map +1 -1
- package/dist/data/data-runtime.d.ts +28 -0
- package/dist/data/data-runtime.d.ts.map +1 -0
- package/dist/data/data-runtime.js +114 -0
- package/dist/data/data-runtime.js.map +1 -0
- package/dist/data/index.d.ts +6 -142
- package/dist/data/index.js +5 -539
- package/dist/data/invalidation.d.ts +9 -0
- package/dist/data/invalidation.d.ts.map +1 -0
- package/dist/data/invalidation.js +27 -0
- package/dist/data/invalidation.js.map +1 -0
- package/dist/data/mutation-cell.d.ts +28 -0
- package/dist/data/mutation-cell.d.ts.map +1 -0
- package/dist/data/mutation-cell.js +132 -0
- package/dist/data/mutation-cell.js.map +1 -0
- package/dist/data/query-cell.d.ts +46 -0
- package/dist/data/query-cell.d.ts.map +1 -0
- package/dist/data/query-cell.js +290 -0
- package/dist/data/query-cell.js.map +1 -0
- package/dist/data/query-key.js +42 -0
- package/dist/data/query-key.js.map +1 -0
- package/dist/data/shared.js +20 -0
- package/dist/data/shared.js.map +1 -0
- package/dist/data/types.d.ts +161 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/foundations/icon/icon.d.ts.map +1 -1
- package/dist/foundations/icon/icon.js.map +1 -1
- package/dist/foundations/structures/portal.d.ts +1 -1
- package/dist/foundations/structures/portal.d.ts.map +1 -1
- package/dist/foundations/structures/portal.js +2 -1
- package/dist/foundations/structures/portal.js.map +1 -1
- package/dist/fx/fx.d.ts +1 -1
- package/dist/fx/fx.js +5 -4
- package/dist/fx/fx.js.map +1 -1
- package/dist/fx/timing.d.ts.map +1 -1
- package/dist/fx/timing.js +10 -6
- package/dist/fx/timing.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/jsx/index.d.ts +2 -1
- package/dist/jsx/index.js +3 -2
- package/dist/jsx/types.d.ts +2 -0
- package/dist/jsx/types.js +2 -1
- package/dist/jsx-runtime2.d.ts +2 -1
- package/dist/jsx-runtime2.js +3 -2
- package/dist/renderer/attributes.js +231 -0
- package/dist/renderer/attributes.js.map +1 -0
- package/dist/renderer/boundaries.js +266 -0
- package/dist/renderer/boundaries.js.map +1 -0
- package/dist/renderer/child-shape.js +85 -0
- package/dist/renderer/child-shape.js.map +1 -0
- package/dist/renderer/children.js +3 -2
- package/dist/renderer/children.js.map +1 -1
- package/dist/renderer/cleanup.js +2 -1
- package/dist/renderer/cleanup.js.map +1 -1
- package/dist/renderer/component-host-cleanup.js +68 -0
- package/dist/renderer/component-host-cleanup.js.map +1 -0
- package/dist/renderer/component-host-instances.js +65 -0
- package/dist/renderer/component-host-instances.js.map +1 -0
- package/dist/renderer/component-host.js +247 -0
- package/dist/renderer/component-host.js.map +1 -0
- package/dist/renderer/dom-host.js +13 -0
- package/dist/renderer/dom-host.js.map +1 -0
- package/dist/renderer/dom-internal.js +185 -0
- package/dist/renderer/dom-internal.js.map +1 -0
- package/dist/renderer/dom.js +9 -2356
- package/dist/renderer/element-children.js +279 -0
- package/dist/renderer/element-children.js.map +1 -0
- package/dist/renderer/env.js +2 -1
- package/dist/renderer/error-boundary-dom.js +29 -0
- package/dist/renderer/error-boundary-dom.js.map +1 -0
- package/dist/renderer/evaluate-dom-range.js +85 -0
- package/dist/renderer/evaluate-dom-range.js.map +1 -0
- package/dist/renderer/evaluate-reconcile.js +281 -0
- package/dist/renderer/evaluate-reconcile.js.map +1 -0
- package/dist/renderer/evaluate.js +13 -399
- package/dist/renderer/evaluate.js.map +1 -1
- package/dist/renderer/fastpath.js +6 -5
- package/dist/renderer/fastpath.js.map +1 -1
- package/dist/renderer/for-commit-dom-map.js +83 -0
- package/dist/renderer/for-commit-dom-map.js.map +1 -0
- package/dist/renderer/for-commit-removal.js +36 -0
- package/dist/renderer/for-commit-removal.js.map +1 -0
- package/dist/renderer/for-commit-reorder.js +89 -0
- package/dist/renderer/for-commit-reorder.js.map +1 -0
- package/dist/renderer/for-commit.js +6 -188
- package/dist/renderer/for-commit.js.map +1 -1
- package/dist/renderer/index.js +28 -16
- package/dist/renderer/index.js.map +1 -1
- package/dist/renderer/keyed-children.js +32 -0
- package/dist/renderer/keyed-children.js.map +1 -0
- package/dist/renderer/keyed.js +2 -15
- package/dist/renderer/keyed.js.map +1 -1
- package/dist/renderer/namespaces.js +23 -0
- package/dist/renderer/namespaces.js.map +1 -0
- package/dist/renderer/prop-bindings.js +280 -0
- package/dist/renderer/prop-bindings.js.map +1 -0
- package/dist/renderer/reactive-child-dom.js +133 -0
- package/dist/renderer/reactive-child-dom.js.map +1 -0
- package/dist/renderer/reactive-child-sources.js +184 -0
- package/dist/renderer/reactive-child-sources.js.map +1 -0
- package/dist/renderer/reactive-children.js +294 -0
- package/dist/renderer/reactive-children.js.map +1 -0
- package/dist/renderer/reconcile-commit.js +38 -0
- package/dist/renderer/reconcile-commit.js.map +1 -0
- package/dist/renderer/reconcile-fastpaths.js +106 -0
- package/dist/renderer/reconcile-fastpaths.js.map +1 -0
- package/dist/renderer/reconcile-resolution.js +187 -0
- package/dist/renderer/reconcile-resolution.js.map +1 -0
- package/dist/renderer/reconcile.js +9 -371
- package/dist/renderer/reconcile.js.map +1 -1
- package/dist/renderer/retained-element-rollback.js +276 -0
- package/dist/renderer/retained-element-rollback.js.map +1 -0
- package/dist/renderer/stable-patch.js +82 -0
- package/dist/renderer/stable-patch.js.map +1 -0
- package/dist/renderer/static-reuse.js +96 -0
- package/dist/renderer/static-reuse.js.map +1 -0
- package/dist/renderer/types.js +2 -1
- package/dist/renderer/utils.js +4 -4
- package/dist/renderer/utils.js.map +1 -1
- package/dist/resources/index.d.ts +3 -2
- package/dist/resources/index.js +5 -2
- package/dist/router/access.js +36 -0
- package/dist/router/access.js.map +1 -0
- package/dist/router/activity.d.ts +10 -0
- package/dist/router/activity.d.ts.map +1 -0
- package/dist/router/activity.js +89 -0
- package/dist/router/activity.js.map +1 -0
- package/dist/router/authoring.d.ts +22 -0
- package/dist/router/authoring.d.ts.map +1 -0
- package/dist/router/authoring.js +198 -0
- package/dist/router/authoring.js.map +1 -0
- package/dist/router/index.d.ts +12 -4
- package/dist/router/index.js +9 -2
- package/dist/router/internal-types.d.ts +31 -0
- package/dist/router/internal-types.d.ts.map +1 -0
- package/dist/router/lazy.d.ts +19 -0
- package/dist/router/lazy.d.ts.map +1 -0
- package/dist/router/lazy.js +52 -0
- package/dist/router/lazy.js.map +1 -0
- package/dist/router/manifest.d.ts +10 -0
- package/dist/router/manifest.d.ts.map +1 -0
- package/dist/router/manifest.js +49 -0
- package/dist/router/manifest.js.map +1 -0
- package/dist/router/navigate.d.ts +4 -33
- package/dist/router/navigate.d.ts.map +1 -1
- package/dist/router/navigate.js +17 -414
- package/dist/router/navigate.js.map +1 -1
- package/dist/router/navigation-registry.d.ts +32 -0
- package/dist/router/navigation-registry.d.ts.map +1 -0
- package/dist/router/navigation-registry.js +105 -0
- package/dist/router/navigation-registry.js.map +1 -0
- package/dist/router/navigation-scroll.d.ts +14 -0
- package/dist/router/navigation-scroll.d.ts.map +1 -0
- package/dist/router/navigation-scroll.js +93 -0
- package/dist/router/navigation-scroll.js.map +1 -0
- package/dist/router/navigation-targets.d.ts +31 -0
- package/dist/router/navigation-targets.d.ts.map +1 -0
- package/dist/router/navigation-targets.js +253 -0
- package/dist/router/navigation-targets.js.map +1 -0
- package/dist/router/policy.d.ts +7 -1
- package/dist/router/policy.d.ts.map +1 -1
- package/dist/router/policy.js +27 -9
- package/dist/router/policy.js.map +1 -1
- package/dist/router/rendering.d.ts +10 -0
- package/dist/router/rendering.d.ts.map +1 -0
- package/dist/router/rendering.js +45 -0
- package/dist/router/rendering.js.map +1 -0
- package/dist/router/resolution.d.ts +17 -0
- package/dist/router/resolution.d.ts.map +1 -0
- package/dist/router/resolution.js +253 -0
- package/dist/router/resolution.js.map +1 -0
- package/dist/router/route-query.d.ts +17 -0
- package/dist/router/route-query.d.ts.map +1 -0
- package/dist/router/route-query.js +47 -0
- package/dist/router/route-query.js.map +1 -0
- package/dist/router/route.d.ts +8 -149
- package/dist/router/route.js +8 -854
- package/dist/router/store.d.ts +50 -0
- package/dist/router/store.d.ts.map +1 -0
- package/dist/router/store.js +171 -0
- package/dist/router/store.js.map +1 -0
- package/dist/runtime/access.js +45 -0
- package/dist/runtime/access.js.map +1 -0
- package/dist/runtime/child-scope.d.ts +1 -1
- package/dist/runtime/child-scope.js +4 -1
- package/dist/runtime/child-scope.js.map +1 -1
- package/dist/runtime/component-cleanup.d.ts +16 -0
- package/dist/runtime/component-cleanup.d.ts.map +1 -0
- package/dist/runtime/component-cleanup.js +70 -0
- package/dist/runtime/component-cleanup.js.map +1 -0
- package/dist/runtime/component-commit.js +165 -0
- package/dist/runtime/component-commit.js.map +1 -0
- package/dist/runtime/component-contracts.js +5 -0
- package/dist/runtime/component-facade.d.ts +5 -0
- package/dist/runtime/component-facade.js +4 -0
- package/dist/runtime/component-internal.d.ts +100 -0
- package/dist/runtime/component-internal.d.ts.map +1 -0
- package/dist/runtime/component-internal.js +219 -0
- package/dist/runtime/component-internal.js.map +1 -0
- package/dist/runtime/component-lifecycle.d.ts +49 -0
- package/dist/runtime/component-lifecycle.d.ts.map +1 -0
- package/dist/runtime/component-lifecycle.js +176 -0
- package/dist/runtime/component-lifecycle.js.map +1 -0
- package/dist/runtime/component-scope.d.ts +55 -0
- package/dist/runtime/component-scope.d.ts.map +1 -0
- package/dist/runtime/component-scope.js +154 -0
- package/dist/runtime/component-scope.js.map +1 -0
- package/dist/runtime/component.d.ts +4 -152
- package/dist/runtime/component.js +4 -692
- package/dist/runtime/context.d.ts +1 -1
- package/dist/runtime/context.js +6 -4
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/control.d.ts +3 -3
- package/dist/runtime/control.js +2 -1
- package/dist/runtime/control.js.map +1 -1
- package/dist/runtime/derive.d.ts.map +1 -1
- package/dist/runtime/derive.js +6 -5
- package/dist/runtime/derive.js.map +1 -1
- package/dist/runtime/effect.d.ts +1 -1
- package/dist/runtime/effect.d.ts.map +1 -1
- package/dist/runtime/effect.js +2 -2
- package/dist/runtime/effect.js.map +1 -1
- package/dist/runtime/events.js +3 -3
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/fastlane.js +13 -27
- package/dist/runtime/fastlane.js.map +1 -1
- package/dist/runtime/for-bench.d.ts +1 -1
- package/dist/runtime/for-bench.js +1 -4
- package/dist/runtime/for-bench.js.map +1 -1
- package/dist/runtime/for-internal.d.ts +43 -0
- package/dist/runtime/for-internal.d.ts.map +1 -0
- package/dist/runtime/for-internal.js +98 -0
- package/dist/runtime/for-internal.js.map +1 -0
- package/dist/runtime/for-reconcile.d.ts +8 -0
- package/dist/runtime/for-reconcile.d.ts.map +1 -0
- package/dist/runtime/for-reconcile.js +389 -0
- package/dist/runtime/for-reconcile.js.map +1 -0
- package/dist/runtime/for-scopes.d.ts +26 -0
- package/dist/runtime/for-scopes.d.ts.map +1 -0
- package/dist/runtime/for-scopes.js +160 -0
- package/dist/runtime/for-scopes.js.map +1 -0
- package/dist/runtime/for-signals.d.ts +30 -0
- package/dist/runtime/for-signals.d.ts.map +1 -0
- package/dist/runtime/for-signals.js +139 -0
- package/dist/runtime/for-signals.js.map +1 -0
- package/dist/runtime/for.d.ts +4 -66
- package/dist/runtime/for.js +5 -773
- package/dist/runtime/lifecycle-operations.d.ts +31 -0
- package/dist/runtime/lifecycle-operations.d.ts.map +1 -0
- package/dist/runtime/lifecycle-operations.js +195 -0
- package/dist/runtime/lifecycle-operations.js.map +1 -0
- package/dist/runtime/operations.d.ts +3 -40
- package/dist/runtime/operations.js +2 -357
- package/dist/runtime/readable.d.ts +2 -3
- package/dist/runtime/readable.d.ts.map +1 -1
- package/dist/runtime/readable.js +6 -5
- package/dist/runtime/readable.js.map +1 -1
- package/dist/runtime/resource-cell.js +2 -2
- package/dist/runtime/resource-cell.js.map +1 -1
- package/dist/runtime/resource-operation.d.ts +13 -0
- package/dist/runtime/resource-operation.d.ts.map +1 -0
- package/dist/runtime/resource-operation.js +170 -0
- package/dist/runtime/resource-operation.js.map +1 -0
- package/dist/runtime/runtime.d.ts +42 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.js +59 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime/scheduler.d.ts +5 -1
- package/dist/runtime/scheduler.d.ts.map +1 -1
- package/dist/runtime/scheduler.js +17 -17
- package/dist/runtime/scheduler.js.map +1 -1
- package/dist/runtime/selector.js +4 -3
- package/dist/runtime/selector.js.map +1 -1
- package/dist/runtime/snapshot-source.d.ts +1 -1
- package/dist/runtime/snapshot-source.js +1 -1
- package/dist/runtime/state.js +2 -1
- package/dist/runtime/state.js.map +1 -1
- package/dist/ssg/batch-render.js +2 -1
- package/dist/ssg/batch-render.js.map +1 -1
- package/dist/ssg/create-static-gen.d.ts +9 -3
- package/dist/ssg/create-static-gen.d.ts.map +1 -1
- package/dist/ssg/create-static-gen.js +12 -99
- package/dist/ssg/create-static-gen.js.map +1 -1
- package/dist/ssg/generation-plan.js +70 -0
- package/dist/ssg/generation-plan.js.map +1 -0
- package/dist/ssg/incremental-manifest.js +1 -1
- package/dist/ssg/static-routes.js +101 -0
- package/dist/ssg/static-routes.js.map +1 -0
- package/dist/ssg/types.d.ts +15 -7
- package/dist/ssg/types.d.ts.map +1 -1
- package/dist/ssr/boundaries.js +113 -0
- package/dist/ssr/boundaries.js.map +1 -0
- package/dist/ssr/component-runtime.js +111 -0
- package/dist/ssr/component-runtime.js.map +1 -0
- package/dist/ssr/context.d.ts +3 -1
- package/dist/ssr/context.d.ts.map +1 -1
- package/dist/ssr/context.js +9 -2
- package/dist/ssr/context.js.map +1 -1
- package/dist/ssr/errors.d.ts +2 -0
- package/dist/ssr/errors.js +11 -1
- package/dist/ssr/errors.js.map +1 -1
- package/dist/ssr/escape.js +3 -3
- package/dist/ssr/escape.js.map +1 -1
- package/dist/ssr/hydration-data.js +10 -0
- package/dist/ssr/hydration-data.js.map +1 -0
- package/dist/ssr/hydration-verify.d.ts +12 -0
- package/dist/ssr/hydration-verify.d.ts.map +1 -0
- package/dist/ssr/hydration-verify.js +144 -0
- package/dist/ssr/hydration-verify.js.map +1 -0
- package/dist/ssr/index-internal.d.ts +15 -0
- package/dist/ssr/index-internal.d.ts.map +1 -0
- package/dist/ssr/index-internal.js +19 -0
- package/dist/ssr/index-internal.js.map +1 -0
- package/dist/ssr/index.d.ts +5 -57
- package/dist/ssr/index.js +3 -738
- package/dist/ssr/render-keys.js +9 -32
- package/dist/ssr/render-keys.js.map +1 -1
- package/dist/ssr/render-resolved.d.ts +1 -1
- package/dist/ssr/render-resolved.d.ts.map +1 -1
- package/dist/ssr/render-resolved.js +4 -2
- package/dist/ssr/render-resolved.js.map +1 -1
- package/dist/ssr/render-sync.d.ts +21 -0
- package/dist/ssr/render-sync.d.ts.map +1 -0
- package/dist/ssr/render-sync.js +275 -0
- package/dist/ssr/render-sync.js.map +1 -0
- package/dist/ssr/route-policy-resolution.js +77 -0
- package/dist/ssr/route-policy-resolution.js.map +1 -0
- package/dist/ssr/route-render.d.ts +77 -0
- package/dist/ssr/route-render.d.ts.map +1 -0
- package/dist/ssr/route-render.js +119 -0
- package/dist/ssr/route-render.js.map +1 -0
- package/dist/ssr/sink.d.ts +26 -0
- package/dist/ssr/sink.d.ts.map +1 -0
- package/dist/ssr/types.d.ts +1 -0
- package/dist/ssr/types.d.ts.map +1 -1
- package/dist/ssr/verify-hydration.js.map +1 -1
- package/dist/testing/index.d.ts +1 -2
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +4 -3
- package/dist/data/index.d.ts.map +0 -1
- package/dist/data/index.js.map +0 -1
- package/dist/renderer/dom.js.map +0 -1
- package/dist/router/route.d.ts.map +0 -1
- package/dist/router/route.js.map +0 -1
- package/dist/runtime/component.d.ts.map +0 -1
- package/dist/runtime/component.js.map +0 -1
- package/dist/runtime/for.d.ts.map +0 -1
- package/dist/runtime/for.js.map +0 -1
- package/dist/runtime/operations.d.ts.map +0 -1
- package/dist/runtime/operations.js.map +0 -1
- package/dist/runtime/ssr-bridge.js +0 -24
- package/dist/runtime/ssr-bridge.js.map +0 -1
- package/dist/ssr/index.d.ts.map +0 -1
- package/dist/ssr/index.js.map +0 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { getCurrentInstance } from "./component-scope.js";
|
|
2
|
+
import { cleanupComponent } from "./component-cleanup.js";
|
|
3
|
+
import { captureInlineRenderSnapshot, createComponentInstance, mountInstanceInline, renderComponentInline, warnUnusedStateReads } from "./component-internal.js";
|
|
4
|
+
import "./component.js";
|
|
5
|
+
export { captureInlineRenderSnapshot, cleanupComponent, createComponentInstance, getCurrentInstance, mountInstanceInline, renderComponentInline, warnUnusedStateReads };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { cleanupComponent, registerOwnedChildScope, unregisterOwnedChildScope } from "./component-cleanup.js";
|
|
2
|
+
import { ComponentInstance } from "./component-internal.js";
|
|
3
|
+
import { getSignal } from "./component-scope.js";
|
|
4
|
+
import { ComponentFunction } from "../common/component.js";
|
|
5
|
+
export { type ComponentFunction, type ComponentInstance, getSignal };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { claimHookIndex, getCurrentComponentInstance, getCurrentInstance, getCurrentPortalScope, getCurrentStateIndex, getSignal, setCurrentComponentInstance } from "./component-scope.js";
|
|
2
|
+
import { cleanupComponent, registerOwnedChildScope, unregisterOwnedChildScope } from "./component-cleanup.js";
|
|
3
|
+
import { captureInlineRenderSnapshot, createComponentInstance, finalizeReadSubscriptions, mountComponent, mountInstanceInline, registerCommitOperation, renderComponentInline, renderScopedComponent, warnUnusedStateReads } from "./component-internal.js";
|
|
4
|
+
export { captureInlineRenderSnapshot, claimHookIndex, cleanupComponent, createComponentInstance, finalizeReadSubscriptions, getCurrentComponentInstance, getCurrentInstance, getCurrentPortalScope, getCurrentStateIndex, getSignal, mountComponent, mountInstanceInline, registerCommitOperation, registerOwnedChildScope, renderComponentInline, renderScopedComponent, setCurrentComponentInstance, unregisterOwnedChildScope, warnUnusedStateReads };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Props } from "../common/props.js";
|
|
2
|
+
import { ReadableSource } from "./readable.js";
|
|
3
|
+
import { State } from "./state.js";
|
|
4
|
+
import { ContextFrame } from "./context.js";
|
|
5
|
+
import { OwnedChildScope, cleanupComponent, registerOwnedChildScope, unregisterOwnedChildScope } from "./component-cleanup.js";
|
|
6
|
+
import { LifecycleOperation } from "./component-lifecycle.js";
|
|
7
|
+
import { ComponentFunction } from "../common/component.js";
|
|
8
|
+
|
|
9
|
+
//#region src/runtime/component-internal.d.ts
|
|
10
|
+
interface ComponentInstance {
|
|
11
|
+
id: string;
|
|
12
|
+
fn: ComponentFunction;
|
|
13
|
+
props: Props;
|
|
14
|
+
target: Element | null;
|
|
15
|
+
parentInstance: ComponentInstance | null;
|
|
16
|
+
portalScope: object | null;
|
|
17
|
+
mounted: boolean;
|
|
18
|
+
abortController: AbortController | null;
|
|
19
|
+
ssr?: boolean;
|
|
20
|
+
cleanupStrict?: boolean;
|
|
21
|
+
stateValues: State<unknown>[];
|
|
22
|
+
evaluationGeneration: number;
|
|
23
|
+
notifyUpdate: (() => void) | null;
|
|
24
|
+
_pendingFlushTask?: () => void;
|
|
25
|
+
_pendingRunTask?: () => void;
|
|
26
|
+
_enqueueRun?: () => void;
|
|
27
|
+
stateIndexCheck: number;
|
|
28
|
+
expectedStateIndices: number[];
|
|
29
|
+
firstRenderComplete: boolean;
|
|
30
|
+
mountOperations: Array<() => void | (() => void) | PromiseLike<void | (() => void)>>;
|
|
31
|
+
commitOperations: Array<() => void | (() => void) | PromiseLike<void | (() => void)>>;
|
|
32
|
+
cleanupFns: Array<() => void>;
|
|
33
|
+
lifecycleSlots: unknown[];
|
|
34
|
+
lifecycleGeneration: number;
|
|
35
|
+
hasPendingUpdate: boolean;
|
|
36
|
+
ownerFrame: ContextFrame | null;
|
|
37
|
+
isRoot?: boolean;
|
|
38
|
+
_currentRenderToken?: number;
|
|
39
|
+
lastRenderToken?: number;
|
|
40
|
+
_pendingReadSources?: Set<ReadableSource<unknown>>;
|
|
41
|
+
_pendingReadSourceVersions?: Map<ReadableSource<unknown>, number>;
|
|
42
|
+
_lastReadSources?: Set<ReadableSource<unknown>>;
|
|
43
|
+
devWarningsEmitted?: Set<string>;
|
|
44
|
+
_placeholder?: Comment;
|
|
45
|
+
_ownedChildScopes?: Set<OwnedChildScope>;
|
|
46
|
+
errorBoundaryState?: {
|
|
47
|
+
error: unknown | null;
|
|
48
|
+
resetKey: unknown;
|
|
49
|
+
notified: boolean;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
declare function createComponentInstance(id: string, fn: ComponentFunction, props: Props, target: Element | null): ComponentInstance;
|
|
53
|
+
/**
|
|
54
|
+
* Register a mount operation that will run after the component is mounted
|
|
55
|
+
* Used by operations (task, on, timer, etc) to execute after render completes
|
|
56
|
+
*/
|
|
57
|
+
declare function captureInlineRenderSnapshot(instance: ComponentInstance): void;
|
|
58
|
+
declare function registerMountOperation(operation: LifecycleOperation): void;
|
|
59
|
+
declare function registerCommitOperation(operation: LifecycleOperation): void;
|
|
60
|
+
declare function commitRenderedComponent(instance: ComponentInstance): void;
|
|
61
|
+
declare function mountInstanceInline(instance: ComponentInstance, target: Element | null): void;
|
|
62
|
+
/**
|
|
63
|
+
* Run a component synchronously: execute function, handle result
|
|
64
|
+
* This is the internal workhorse that manages async continuations and generation tracking.
|
|
65
|
+
* Must always be called through the scheduler.
|
|
66
|
+
*
|
|
67
|
+
* ACTOR INVARIANT: This function is enqueued as a task, never called directly.
|
|
68
|
+
*/
|
|
69
|
+
declare function renderScopedComponent<T>(instance: ComponentInstance, startStateIndex: number, render: () => T): T;
|
|
70
|
+
/**
|
|
71
|
+
* Execute a component's render function synchronously.
|
|
72
|
+
* Returns either a vnode/promise immediately (does NOT render).
|
|
73
|
+
* Rendering happens separately through the scheduled commit helper.
|
|
74
|
+
*/
|
|
75
|
+
declare function renderComponentInline(instance: ComponentInstance): unknown | Promise<unknown>;
|
|
76
|
+
declare function warnUnusedStateReads(instance: ComponentInstance): void;
|
|
77
|
+
/**
|
|
78
|
+
* Public entry point: Execute component with full lifecycle (execute + render)
|
|
79
|
+
* Handles both initial mount and re-execution. Always enqueues through scheduler.
|
|
80
|
+
* Single entry point to avoid lifecycle divergence.
|
|
81
|
+
*/
|
|
82
|
+
declare function executeComponent(instance: ComponentInstance): void;
|
|
83
|
+
/**
|
|
84
|
+
* Finalize read subscriptions for an instance after a successful commit.
|
|
85
|
+
* - Update per-state readers map to point to this instance's last committed token
|
|
86
|
+
* - Remove this instance from states it no longer reads
|
|
87
|
+
* This is deterministic and runs synchronously with commit to ensure
|
|
88
|
+
* subscribers are only notified when they actually read a state in their
|
|
89
|
+
* last committed render.
|
|
90
|
+
*/
|
|
91
|
+
declare function finalizeReadSubscriptions(instance: ComponentInstance): void;
|
|
92
|
+
/**
|
|
93
|
+
* Mount a component instance.
|
|
94
|
+
* This is just an alias to executeComponent() to maintain API compatibility.
|
|
95
|
+
* All lifecycle logic is unified in executeComponent().
|
|
96
|
+
*/
|
|
97
|
+
declare function mountComponent(instance: ComponentInstance): void;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { type ComponentFunction, ComponentInstance, cleanupComponent, registerOwnedChildScope, unregisterOwnedChildScope };
|
|
100
|
+
//# sourceMappingURL=component-internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-internal.d.ts","names":[],"sources":["../../src/runtime/component-internal.ts"],"mappings":";;;;;;;;;UA2DiB,iBAAA;EACf,EAAA;EACA,EAAA,EAAI,iBAAA;EACJ,KAAA,EAAO,KAAA;EACP,MAAA,EAAQ,OAAA;EACR,cAAA,EAAgB,iBAAA;EAChB,WAAA;EACA,OAAA;EACA,eAAA,EAAiB,eAAA;EACjB,GAAA;EAEA,aAAA;EACA,WAAA,EAAa,KAAA;EACb,oBAAA;EACA,YAAA;EAEA,iBAAA;EACA,eAAA;EACA,WAAA;EACA,eAAA;EACA,oBAAA;EACA,mBAAA;EACA,eAAA,EAAiB,KAAA,6BACa,WAAA;EAE9B,gBAAA,EAAkB,KAAA,6BACY,WAAA;EAE9B,UAAA,EAAY,KAAA;EACZ,cAAA;EACA,mBAAA;EACA,gBAAA;EACA,UAAA,EAAY,YAAA;EACZ,MAAA;EAGA,mBAAA;EACA,eAAA;EACA,mBAAA,GAAsB,GAAA,CAAI,cAAA;EAC1B,0BAAA,GAA6B,GAAA,CAAI,cAAA;EACjC,gBAAA,GAAmB,GAAA,CAAI,cAAA;EACvB,kBAAA,GAAqB,GAAA;EAIrB,YAAA,GAAe,OAAA;EACf,iBAAA,GAAoB,GAAA,CAAI,eAAA;EACxB,kBAAA;IACE,KAAA;IACA,QAAA;IACA,QAAA;EAAA;AAAA;AAAA,iBAIY,uBAAA,CACd,EAAA,UACA,EAAA,EAAI,iBAAA,EACJ,KAAA,EAAO,KAAA,EACP,MAAA,EAAQ,OAAA,UACP,iBAAA;;;;;iBA6Ea,2BAAA,CAA4B,QAA2B,EAAjB,iBAAiB;AAAA,iBAIvD,sBAAA,CAAuB,SAA6B,EAAlB,kBAAkB;AAAA,iBAIpD,uBAAA,CAAwB,SAA6B,EAAlB,kBAAkB;AAAA,iBAIrD,uBAAA,CAAwB,QAA2B,EAAjB,iBAAiB;AAAA,iBAInD,mBAAA,CACd,QAAA,EAAU,iBAAA,EACV,MAAA,EAAQ,OAAO;;;;;;;;iBAuCD,qBAAA,IACd,QAAA,EAAU,iBAAA,EACV,eAAA,UACA,MAAA,QAAc,CAAA,GACb,CAAA;;;;;;iBA6Ba,qBAAA,CACd,QAAA,EAAU,iBAAA,aACC,OAAO;AAAA,iBAwCJ,oBAAA,CAAqB,QAA2B,EAAjB,iBAAiB;;;;;;iBAmGhD,gBAAA,CAAiB,QAA2B,EAAjB,iBAAiB;;;;;;;;;iBAmB5C,yBAAA,CAA0B,QAA2B,EAAjB,iBAAiB;;;;AAhVzD;AAIZ;iBAqVgB,cAAA,CAAe,QAA2B,EAAjB,iBAAiB"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { isDevelopmentEnvironment, isProductionEnvironment } from "../common/env.js";
|
|
2
|
+
import { logger } from "../dev/logger.js";
|
|
3
|
+
import { enqueueRuntimeTask } from "./access.js";
|
|
4
|
+
import { withContext } from "./context.js";
|
|
5
|
+
import { finalizeReadableSubscriptions } from "./readable.js";
|
|
6
|
+
import { incDevCounter } from "./dev-namespace.js";
|
|
7
|
+
import { beginRenderTracking, captureInlineComponentScope, captureInlineRenderTracking, clearRenderTracking, enterComponentExecutionScope, enterRenderScopedComponent, exitComponentExecutionScope, getCurrentComponentInstance, getCurrentInstance, getCurrentPortalScope, getSignalForInstance, resetRenderState, restoreInlineComponentScope, restoreInlineRenderTracking, restoreRenderScopedComponent } from "./component-scope.js";
|
|
8
|
+
import { cleanupComponent, registerOwnedChildScope, unregisterOwnedChildScope } from "./component-cleanup.js";
|
|
9
|
+
import { captureInlineRenderSnapshot as captureInlineRenderSnapshot$1, commitLifecycleForInstance, commitRenderedComponent as commitRenderedComponent$1, discardCommitOperations, finalizeInlineReadSubscriptions, registerCommitOperationForInstance } from "./component-lifecycle.js";
|
|
10
|
+
import { runScheduledComponent } from "./component-commit.js";
|
|
11
|
+
//#region src/runtime/component-internal.ts
|
|
12
|
+
function createComponentInstance(id, fn, props, target) {
|
|
13
|
+
const parentInstance = getCurrentInstance();
|
|
14
|
+
const instance = {
|
|
15
|
+
id,
|
|
16
|
+
fn,
|
|
17
|
+
props,
|
|
18
|
+
target,
|
|
19
|
+
parentInstance,
|
|
20
|
+
portalScope: parentInstance?.portalScope ?? getCurrentPortalScope() ?? null,
|
|
21
|
+
mounted: false,
|
|
22
|
+
abortController: null,
|
|
23
|
+
stateValues: [],
|
|
24
|
+
evaluationGeneration: 0,
|
|
25
|
+
notifyUpdate: null,
|
|
26
|
+
_pendingFlushTask: void 0,
|
|
27
|
+
_pendingRunTask: void 0,
|
|
28
|
+
_enqueueRun: void 0,
|
|
29
|
+
stateIndexCheck: -1,
|
|
30
|
+
expectedStateIndices: [],
|
|
31
|
+
firstRenderComplete: false,
|
|
32
|
+
mountOperations: [],
|
|
33
|
+
commitOperations: [],
|
|
34
|
+
cleanupFns: [],
|
|
35
|
+
lifecycleSlots: [],
|
|
36
|
+
lifecycleGeneration: 0,
|
|
37
|
+
hasPendingUpdate: false,
|
|
38
|
+
ownerFrame: null,
|
|
39
|
+
ssr: false,
|
|
40
|
+
cleanupStrict: false,
|
|
41
|
+
isRoot: false,
|
|
42
|
+
_currentRenderToken: void 0,
|
|
43
|
+
lastRenderToken: 0,
|
|
44
|
+
_pendingReadSources: void 0,
|
|
45
|
+
_pendingReadSourceVersions: void 0,
|
|
46
|
+
_lastReadSources: void 0,
|
|
47
|
+
devWarningsEmitted: void 0
|
|
48
|
+
};
|
|
49
|
+
instance._pendingRunTask = () => {
|
|
50
|
+
instance.hasPendingUpdate = false;
|
|
51
|
+
if (instance.notifyUpdate === null) return;
|
|
52
|
+
runScheduledComponent(instance, {
|
|
53
|
+
execute: executeComponentSync,
|
|
54
|
+
finalizeReadSubscriptions,
|
|
55
|
+
warnUnusedStateReads,
|
|
56
|
+
commitRenderedComponent
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
instance._enqueueRun = () => {
|
|
60
|
+
if (!instance.hasPendingUpdate) {
|
|
61
|
+
instance.hasPendingUpdate = true;
|
|
62
|
+
enqueueRuntimeTask(instance._pendingRunTask);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
instance._pendingFlushTask = instance._pendingRunTask;
|
|
66
|
+
return instance;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Register a mount operation that will run after the component is mounted
|
|
70
|
+
* Used by operations (task, on, timer, etc) to execute after render completes
|
|
71
|
+
*/
|
|
72
|
+
function captureInlineRenderSnapshot(instance) {
|
|
73
|
+
captureInlineRenderSnapshot$1(instance);
|
|
74
|
+
}
|
|
75
|
+
function registerCommitOperation(operation) {
|
|
76
|
+
registerCommitOperationForInstance(getCurrentComponentInstance(), operation);
|
|
77
|
+
}
|
|
78
|
+
function commitRenderedComponent(instance) {
|
|
79
|
+
commitRenderedComponent$1(instance);
|
|
80
|
+
}
|
|
81
|
+
function mountInstanceInline(instance, target) {
|
|
82
|
+
instance.target = target;
|
|
83
|
+
try {
|
|
84
|
+
if (target instanceof Element) {
|
|
85
|
+
const host = target;
|
|
86
|
+
const nextInstances = (host.__ASKR_INSTANCES ?? []).filter((entry) => entry !== instance);
|
|
87
|
+
nextInstances.push(instance);
|
|
88
|
+
host.__ASKR_INSTANCES = nextInstances;
|
|
89
|
+
host.__ASKR_INSTANCE = nextInstances[0] ?? instance;
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {}
|
|
92
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
93
|
+
const wasFirstMount = !instance.mounted;
|
|
94
|
+
instance.mounted = true;
|
|
95
|
+
commitLifecycleForInstance(instance, wasFirstMount);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Run a component synchronously: execute function, handle result
|
|
99
|
+
* This is the internal workhorse that manages async continuations and generation tracking.
|
|
100
|
+
* Must always be called through the scheduler.
|
|
101
|
+
*
|
|
102
|
+
* ACTOR INVARIANT: This function is enqueued as a task, never called directly.
|
|
103
|
+
*/
|
|
104
|
+
function renderScopedComponent(instance, startStateIndex, render) {
|
|
105
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
106
|
+
resetRenderState(instance);
|
|
107
|
+
beginRenderTracking(instance);
|
|
108
|
+
const savedScope = enterRenderScopedComponent(instance, startStateIndex);
|
|
109
|
+
let didComplete = false;
|
|
110
|
+
try {
|
|
111
|
+
const result = withContext({
|
|
112
|
+
parent: instance.ownerFrame,
|
|
113
|
+
values: null
|
|
114
|
+
}, render);
|
|
115
|
+
didComplete = true;
|
|
116
|
+
return result;
|
|
117
|
+
} finally {
|
|
118
|
+
if (!didComplete) clearRenderTracking(instance);
|
|
119
|
+
restoreRenderScopedComponent(savedScope);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Execute a component's render function synchronously.
|
|
124
|
+
* Returns either a vnode/promise immediately (does NOT render).
|
|
125
|
+
* Rendering happens separately through the scheduled commit helper.
|
|
126
|
+
*/
|
|
127
|
+
function renderComponentInline(instance) {
|
|
128
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
129
|
+
const trackingSnapshot = captureInlineRenderTracking(instance);
|
|
130
|
+
const scopeSnapshot = captureInlineComponentScope();
|
|
131
|
+
const hadToken = trackingSnapshot.currentRenderToken !== void 0;
|
|
132
|
+
if (!hadToken) beginRenderTracking(instance);
|
|
133
|
+
try {
|
|
134
|
+
const result = executeComponentSync(instance);
|
|
135
|
+
if (!hadToken) finalizeInlineReadSubscriptions(instance, instance._currentRenderToken, instance._pendingReadSources, instance._pendingReadSourceVersions);
|
|
136
|
+
commitRenderedComponent(instance);
|
|
137
|
+
return result;
|
|
138
|
+
} finally {
|
|
139
|
+
restoreInlineRenderTracking(instance, trackingSnapshot);
|
|
140
|
+
restoreInlineComponentScope(scopeSnapshot);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function warnUnusedStateReads(instance) {
|
|
144
|
+
for (let i = 0; i < instance.stateValues.length; i++) {
|
|
145
|
+
const state = instance.stateValues[i];
|
|
146
|
+
const hasCommittedUsage = (state?._readers?.size ?? 0) > 0 || (state?._derivedSubscribers?.size ?? 0) > 0;
|
|
147
|
+
if (state && !state._hasBeenRead && !state._hasEverBeenRead && !hasCommittedUsage) try {
|
|
148
|
+
const name = instance.fn?.name || "<anonymous>";
|
|
149
|
+
warnInstanceOnce(instance, `unused-state:${i}`, `[askr] Unused state variable detected in ${name} at index ${i}. State should be read during render or removed.`);
|
|
150
|
+
} catch {
|
|
151
|
+
warnInstanceOnce(instance, `unused-state:${i}`, `[askr] Unused state variable detected. State should be read during render or removed.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function executeComponentSync(instance) {
|
|
156
|
+
resetRenderState(instance);
|
|
157
|
+
incDevCounter("componentRuns");
|
|
158
|
+
incDevCounter("componentReruns");
|
|
159
|
+
const savedPortalScope = enterComponentExecutionScope(instance);
|
|
160
|
+
let didComplete = false;
|
|
161
|
+
try {
|
|
162
|
+
const renderStartTime = isDevelopmentEnvironment() ? Date.now() : 0;
|
|
163
|
+
const context = { get signal() {
|
|
164
|
+
return getSignalForInstance(instance);
|
|
165
|
+
} };
|
|
166
|
+
const result = withContext({
|
|
167
|
+
parent: instance.ownerFrame,
|
|
168
|
+
values: null
|
|
169
|
+
}, () => instance.fn(instance.props, context));
|
|
170
|
+
const renderTime = Date.now() - renderStartTime;
|
|
171
|
+
if (renderTime > 5) warnInstanceOnce(instance, "slow-render", `[askr] Slow render detected: ${renderTime}ms. Consider optimizing component performance.`);
|
|
172
|
+
if (!instance.firstRenderComplete) instance.firstRenderComplete = true;
|
|
173
|
+
didComplete = true;
|
|
174
|
+
return result;
|
|
175
|
+
} finally {
|
|
176
|
+
if (!didComplete) discardCommitOperations(instance);
|
|
177
|
+
exitComponentExecutionScope(savedPortalScope);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Public entry point: Execute component with full lifecycle (execute + render)
|
|
182
|
+
* Handles both initial mount and re-execution. Always enqueues through scheduler.
|
|
183
|
+
* Single entry point to avoid lifecycle divergence.
|
|
184
|
+
*/
|
|
185
|
+
function executeComponent(instance) {
|
|
186
|
+
instance.abortController = null;
|
|
187
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
188
|
+
enqueueRuntimeTask(instance._pendingRunTask);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Finalize read subscriptions for an instance after a successful commit.
|
|
192
|
+
* - Update per-state readers map to point to this instance's last committed token
|
|
193
|
+
* - Remove this instance from states it no longer reads
|
|
194
|
+
* This is deterministic and runs synchronously with commit to ensure
|
|
195
|
+
* subscribers are only notified when they actually read a state in their
|
|
196
|
+
* last committed render.
|
|
197
|
+
*/
|
|
198
|
+
function finalizeReadSubscriptions(instance) {
|
|
199
|
+
finalizeReadableSubscriptions(instance);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Mount a component instance.
|
|
203
|
+
* This is just an alias to executeComponent() to maintain API compatibility.
|
|
204
|
+
* All lifecycle logic is unified in executeComponent().
|
|
205
|
+
*/
|
|
206
|
+
function mountComponent(instance) {
|
|
207
|
+
executeComponent(instance);
|
|
208
|
+
}
|
|
209
|
+
function warnInstanceOnce(instance, key, message) {
|
|
210
|
+
if (isProductionEnvironment()) return;
|
|
211
|
+
const warnings = instance.devWarningsEmitted ??= /* @__PURE__ */ new Set();
|
|
212
|
+
if (warnings.has(key)) return;
|
|
213
|
+
warnings.add(key);
|
|
214
|
+
logger.warn(message);
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
export { captureInlineRenderSnapshot, cleanupComponent, commitRenderedComponent, createComponentInstance, executeComponent, finalizeReadSubscriptions, mountComponent, mountInstanceInline, registerCommitOperation, registerOwnedChildScope, renderComponentInline, renderScopedComponent, unregisterOwnedChildScope, warnUnusedStateReads };
|
|
218
|
+
|
|
219
|
+
//# sourceMappingURL=component-internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-internal.js","names":[],"sources":["../../src/runtime/component-internal.ts"],"sourcesContent":["/**\n * Component instance lifecycle management\n * Internal only — users never see this\n */\n\nimport { type State } from './state';\nimport { enqueueRuntimeTask } from './access';\nimport type { Props } from '../common/props';\nimport type { ComponentFunction } from '../common/component';\nimport {\n // withContext is the sole primitive for context restoration\n withContext,\n type ContextFrame,\n} from './context';\nimport { type ReadableSource, finalizeReadableSubscriptions } from './readable';\nimport {\n isDevelopmentEnvironment,\n isProductionEnvironment,\n} from '../common/env';\nimport { logger } from '../dev/logger';\nimport { incDevCounter } from './dev-namespace';\nimport {\n cleanupComponent,\n registerOwnedChildScope,\n unregisterOwnedChildScope,\n type OwnedChildScope,\n} from './component-cleanup';\nimport { runScheduledComponent } from './component-commit';\nimport {\n captureInlineRenderSnapshot as captureLifecycleInlineRenderSnapshot,\n commitLifecycleForInstance,\n commitRenderedComponent as commitRenderedLifecycleComponent,\n discardCommitOperations,\n finalizeInlineReadSubscriptions,\n registerCommitOperationForInstance,\n registerMountOperationForInstance,\n type LifecycleOperation,\n} from './component-lifecycle';\nimport {\n beginRenderTracking,\n captureInlineComponentScope,\n captureInlineRenderTracking,\n clearRenderTracking,\n enterComponentExecutionScope,\n enterRenderScopedComponent,\n exitComponentExecutionScope,\n getCurrentComponentInstance,\n getCurrentInstance,\n getCurrentPortalScope,\n getSignalForInstance,\n resetRenderState,\n restoreInlineComponentScope,\n restoreInlineRenderTracking,\n restoreRenderScopedComponent,\n} from './component-scope';\n\nexport type { ComponentFunction } from '../common/component';\nexport { cleanupComponent, registerOwnedChildScope, unregisterOwnedChildScope };\n\nexport interface ComponentInstance {\n id: string;\n fn: ComponentFunction;\n props: Props;\n target: Element | null;\n parentInstance: ComponentInstance | null;\n portalScope: object | null;\n mounted: boolean;\n abortController: AbortController | null; // Lazily created per-component abort lifecycle\n ssr?: boolean; // Set to true for SSR temporary instances\n // Opt-in strict cleanup mode: when true cleanup errors are aggregated and re-thrown\n cleanupStrict?: boolean;\n stateValues: State<unknown>[]; // Persistent state storage across renders\n evaluationGeneration: number; // Prevents stale async evaluation completions\n notifyUpdate: (() => void) | null; // Callback for state updates (persisted on instance)\n // Internal: prebound helpers to avoid per-update closures (allocation hot-path)\n _pendingFlushTask?: () => void; // Clears hasPendingUpdate and triggers notifyUpdate\n _pendingRunTask?: () => void; // Clears hasPendingUpdate and runs component\n _enqueueRun?: () => void; // Batches run requests and enqueues _pendingRunTask\n stateIndexCheck: number; // Track state indices to catch conditional calls\n expectedStateIndices: number[]; // Expected sequence of render-scoped hook indices (frozen after first render)\n firstRenderComplete: boolean; // Flag to detect transition from first to subsequent renders\n mountOperations: Array<\n () => void | (() => void) | PromiseLike<void | (() => void)>\n >; // Operations to run when component mounts\n commitOperations: Array<\n () => void | (() => void) | PromiseLike<void | (() => void)>\n >; // Operations to run after a successful committed render\n cleanupFns: Array<() => void>; // Cleanup functions to run on unmount\n lifecycleSlots: unknown[]; // Render-scoped lifecycle primitive storage\n lifecycleGeneration: number; // Invalidates async mount-operation settlement after disposal\n hasPendingUpdate: boolean; // Flag to batch state updates (coalescing)\n ownerFrame: ContextFrame | null; // Provider chain for this component (set by Scope, never overwritten)\n isRoot?: boolean;\n\n // Render-tracking for precise subscriptions (internal)\n _currentRenderToken?: number; // Token for the in-progress render (set before render)\n lastRenderToken?: number; // Token of the last *committed* render\n _pendingReadSources?: Set<ReadableSource<unknown>>; // Readables read during the in-progress render\n _pendingReadSourceVersions?: Map<ReadableSource<unknown>, number>; // Source versions captured during the in-progress render\n _lastReadSources?: Set<ReadableSource<unknown>>; // Readables read during the last committed render\n devWarningsEmitted?: Set<string>; // Dev-only warning dedupe for this instance\n\n // Placeholder for null-returning components. When a component initially returns\n // null, we create a comment placeholder so updates can replace it with content.\n _placeholder?: Comment;\n _ownedChildScopes?: Set<OwnedChildScope>;\n errorBoundaryState?: {\n error: unknown | null;\n resetKey: unknown;\n notified: boolean;\n };\n}\n\nexport function createComponentInstance(\n id: string,\n fn: ComponentFunction,\n props: Props,\n target: Element | null\n): ComponentInstance {\n const parentInstance = getCurrentInstance();\n const portalScope = parentInstance?.portalScope ?? getCurrentPortalScope();\n const instance: ComponentInstance = {\n id,\n fn,\n props,\n target,\n parentInstance,\n portalScope: portalScope ?? null,\n mounted: false,\n abortController: null,\n stateValues: [],\n evaluationGeneration: 0,\n notifyUpdate: null,\n // Prebound helpers (initialized below) to avoid per-update allocations\n _pendingFlushTask: undefined,\n _pendingRunTask: undefined,\n _enqueueRun: undefined,\n stateIndexCheck: -1,\n expectedStateIndices: [],\n firstRenderComplete: false,\n mountOperations: [],\n commitOperations: [],\n cleanupFns: [],\n lifecycleSlots: [],\n lifecycleGeneration: 0,\n hasPendingUpdate: false,\n ownerFrame: null, // Will be set by renderer when vnode is marked\n ssr: false,\n cleanupStrict: false,\n isRoot: false,\n\n // Render-tracking (for precise state subscriptions)\n _currentRenderToken: undefined,\n lastRenderToken: 0,\n _pendingReadSources: undefined,\n _pendingReadSourceVersions: undefined,\n _lastReadSources: undefined,\n devWarningsEmitted: undefined,\n };\n\n // Initialize prebound helper tasks once per instance to avoid allocations\n instance._pendingRunTask = () => {\n // Clear pending flag when the run task executes\n instance.hasPendingUpdate = false;\n if (instance.notifyUpdate === null) {\n return;\n }\n // Execute component run (will set up notifyUpdate before render)\n runScheduledComponent(instance, {\n execute: executeComponentSync,\n finalizeReadSubscriptions,\n warnUnusedStateReads,\n commitRenderedComponent,\n });\n };\n\n instance._enqueueRun = () => {\n if (!instance.hasPendingUpdate) {\n instance.hasPendingUpdate = true;\n // Enqueue single run task (coalesces multiple writes)\n enqueueRuntimeTask(instance._pendingRunTask!);\n }\n };\n\n // Default state-driven updates enqueue the run task directly. Specialized\n // runtimes (for example `For` item instances) can still override this hook.\n instance._pendingFlushTask = instance._pendingRunTask;\n\n return instance;\n}\n\n/**\n * Register a mount operation that will run after the component is mounted\n * Used by operations (task, on, timer, etc) to execute after render completes\n */\nexport function captureInlineRenderSnapshot(instance: ComponentInstance): void {\n captureLifecycleInlineRenderSnapshot(instance);\n}\n\nexport function registerMountOperation(operation: LifecycleOperation): void {\n registerMountOperationForInstance(getCurrentComponentInstance(), operation);\n}\n\nexport function registerCommitOperation(operation: LifecycleOperation): void {\n registerCommitOperationForInstance(getCurrentComponentInstance(), operation);\n}\n\nexport function commitRenderedComponent(instance: ComponentInstance): void {\n commitRenderedLifecycleComponent(instance);\n}\n\nexport function mountInstanceInline(\n instance: ComponentInstance,\n target: Element | null\n): void {\n instance.target = target;\n // Record backref on host element so renderer can clean up when the\n // node is removed. Avoids leaks if the node is detached or replaced.\n try {\n if (target instanceof Element) {\n const host = target as Element & {\n __ASKR_INSTANCE?: ComponentInstance;\n __ASKR_INSTANCES?: ComponentInstance[];\n };\n const instances = host.__ASKR_INSTANCES ?? [];\n const nextInstances = instances.filter((entry) => entry !== instance);\n nextInstances.push(instance);\n host.__ASKR_INSTANCES = nextInstances;\n host.__ASKR_INSTANCE = nextInstances[0] ?? instance;\n }\n } catch (err) {\n void err;\n }\n\n // Ensure notifyUpdate is available for async resource completions that may\n // try to trigger re-render. This mirrors the setup in executeComponent().\n // Use prebound enqueue helper to avoid allocating a new closure\n instance.notifyUpdate = instance._enqueueRun!;\n\n const wasFirstMount = !instance.mounted;\n instance.mounted = true;\n commitLifecycleForInstance(instance, wasFirstMount);\n}\n\n/**\n * Run a component synchronously: execute function, handle result\n * This is the internal workhorse that manages async continuations and generation tracking.\n * Must always be called through the scheduler.\n *\n * ACTOR INVARIANT: This function is enqueued as a task, never called directly.\n */\n\nexport function renderScopedComponent<T>(\n instance: ComponentInstance,\n startStateIndex: number,\n render: () => T\n): T {\n instance.notifyUpdate = instance._enqueueRun!;\n resetRenderState(instance);\n beginRenderTracking(instance);\n const savedScope = enterRenderScopedComponent(instance, startStateIndex);\n\n let didComplete = false;\n\n try {\n const executionFrame: ContextFrame = {\n parent: instance.ownerFrame,\n values: null,\n };\n const result = withContext(executionFrame, render);\n didComplete = true;\n return result;\n } finally {\n if (!didComplete) {\n clearRenderTracking(instance);\n }\n restoreRenderScopedComponent(savedScope);\n }\n}\n\n/**\n * Execute a component's render function synchronously.\n * Returns either a vnode/promise immediately (does NOT render).\n * Rendering happens separately through the scheduled commit helper.\n */\nexport function renderComponentInline(\n instance: ComponentInstance\n): unknown | Promise<unknown> {\n // Reused inline instances can cross renderer cleanup boundaries while their\n // host node is retained. Make sure state writes still enqueue this instance.\n instance.notifyUpdate = instance._enqueueRun!;\n\n // Ensure inline executions (rendered during parent's evaluate) still\n // receive a render token and have their state reads finalized so\n // subscriptions are correctly recorded. If this function is called\n // as part of a scheduled run, the token will already be set by\n // runComponent and we should not overwrite it.\n const trackingSnapshot = captureInlineRenderTracking(instance);\n const scopeSnapshot = captureInlineComponentScope();\n const hadToken = trackingSnapshot.currentRenderToken !== undefined;\n\n if (!hadToken) {\n beginRenderTracking(instance);\n }\n\n try {\n const result = executeComponentSync(instance);\n // If we set the token for inline execution, finalize subscriptions now\n // unless the parent DOM commit is still provisional. Renderer commit\n // batches flush these reads only after DOM evaluation succeeds.\n if (!hadToken) {\n finalizeInlineReadSubscriptions(\n instance,\n instance._currentRenderToken!,\n instance._pendingReadSources,\n instance._pendingReadSourceVersions\n );\n }\n commitRenderedComponent(instance);\n return result;\n } finally {\n // Restore previous token/read states for nested inline render scenarios\n restoreInlineRenderTracking(instance, trackingSnapshot);\n restoreInlineComponentScope(scopeSnapshot);\n }\n}\n\nexport function warnUnusedStateReads(instance: ComponentInstance): void {\n for (let i = 0; i < instance.stateValues.length; i++) {\n const state = instance.stateValues[i];\n const hasCommittedUsage =\n (state?._readers?.size ?? 0) > 0 ||\n ((state as { _derivedSubscribers?: Set<unknown> } | undefined)\n ?._derivedSubscribers?.size ?? 0) > 0;\n\n if (\n state &&\n !state._hasBeenRead &&\n !state._hasEverBeenRead &&\n !hasCommittedUsage\n ) {\n try {\n const name = instance.fn?.name || '<anonymous>';\n warnInstanceOnce(\n instance,\n `unused-state:${i}`,\n `[askr] Unused state variable detected in ${name} at index ${i}. State should be read during render or removed.`\n );\n } catch {\n warnInstanceOnce(\n instance,\n `unused-state:${i}`,\n `[askr] Unused state variable detected. State should be read during render or removed.`\n );\n }\n }\n }\n}\n\nfunction executeComponentSync(\n instance: ComponentInstance\n): unknown | Promise<unknown> {\n resetRenderState(instance);\n incDevCounter('componentRuns');\n incDevCounter('componentReruns');\n\n const savedPortalScope = enterComponentExecutionScope(instance);\n\n let didComplete = false;\n\n try {\n // Track render time in dev mode\n const renderStartTime = isDevelopmentEnvironment() ? Date.now() : 0;\n\n // Create context object with abort signal\n const context = {\n get signal(): AbortSignal {\n return getSignalForInstance(instance);\n },\n };\n\n // Execute component within its owner frame (provider chain).\n // This ensures all context reads see the correct provider values.\n // We create a new execution frame whose parent is the ownerFrame. The\n // `values` map is lazily allocated to avoid per-render Map allocations\n // for components that do not use context.\n const executionFrame: ContextFrame = {\n parent: instance.ownerFrame,\n values: null,\n };\n const result = withContext(executionFrame, () =>\n instance.fn(instance.props, context)\n );\n\n // Check render time\n const renderTime = Date.now() - renderStartTime;\n if (renderTime > 5) {\n warnInstanceOnce(\n instance,\n 'slow-render',\n `[askr] Slow render detected: ${renderTime}ms. Consider optimizing component performance.`\n );\n }\n\n // Mark first render complete after successful execution\n // This enables hook order validation on subsequent renders\n if (!instance.firstRenderComplete) {\n instance.firstRenderComplete = true;\n }\n\n didComplete = true;\n return result;\n } finally {\n if (!didComplete) {\n discardCommitOperations(instance);\n }\n // Synchronous path: we did not push a fresh frame, so nothing to pop here.\n exitComponentExecutionScope(savedPortalScope);\n }\n}\n\n/**\n * Public entry point: Execute component with full lifecycle (execute + render)\n * Handles both initial mount and re-execution. Always enqueues through scheduler.\n * Single entry point to avoid lifecycle divergence.\n */\nexport function executeComponent(instance: ComponentInstance): void {\n // Lazily recreate abort controller only when signal is actually requested.\n instance.abortController = null;\n\n // Setup notifyUpdate callback using prebound helper to avoid per-call closures\n instance.notifyUpdate = instance._enqueueRun!;\n\n // Enqueue the initial component run\n enqueueRuntimeTask(instance._pendingRunTask!);\n}\n\n/**\n * Finalize read subscriptions for an instance after a successful commit.\n * - Update per-state readers map to point to this instance's last committed token\n * - Remove this instance from states it no longer reads\n * This is deterministic and runs synchronously with commit to ensure\n * subscribers are only notified when they actually read a state in their\n * last committed render.\n */\nexport function finalizeReadSubscriptions(instance: ComponentInstance): void {\n finalizeReadableSubscriptions(instance);\n}\n\n/**\n * Mount a component instance.\n * This is just an alias to executeComponent() to maintain API compatibility.\n * All lifecycle logic is unified in executeComponent().\n */\nexport function mountComponent(instance: ComponentInstance): void {\n executeComponent(instance);\n}\n\nfunction warnInstanceOnce(\n instance: ComponentInstance,\n key: string,\n message: string\n): void {\n if (isProductionEnvironment()) return;\n const warnings = (instance.devWarningsEmitted ??= new Set());\n if (warnings.has(key)) return;\n warnings.add(key);\n logger.warn(message);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Props } from "../common/props.js";
|
|
2
|
+
import { ReadableSource } from "./readable.js";
|
|
3
|
+
import { ContextFrame } from "./context.js";
|
|
4
|
+
import { ComponentInstance } from "./component-internal.js";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime/component-lifecycle.d.ts
|
|
7
|
+
type LifecycleOperation = () => void | (() => void) | PromiseLike<void | (() => void)>;
|
|
8
|
+
type LifecycleCommitBatchEntry = {
|
|
9
|
+
instance: ComponentInstance;
|
|
10
|
+
wasFirstMount: boolean;
|
|
11
|
+
};
|
|
12
|
+
type ReadSubscriptionCommit = {
|
|
13
|
+
instance: ComponentInstance;
|
|
14
|
+
token: number;
|
|
15
|
+
pendingReadSources: Set<ReadableSource<unknown>> | undefined;
|
|
16
|
+
pendingReadSourceVersions: Map<ReadableSource<unknown>, number> | undefined;
|
|
17
|
+
};
|
|
18
|
+
type InlineRenderSnapshot = {
|
|
19
|
+
instance: ComponentInstance;
|
|
20
|
+
props: Props;
|
|
21
|
+
ownerFrame: ContextFrame | null;
|
|
22
|
+
portalScope: object | null;
|
|
23
|
+
parentInstance: ComponentInstance | null;
|
|
24
|
+
isRoot: boolean | undefined;
|
|
25
|
+
};
|
|
26
|
+
type LifecycleCommitBatch = {
|
|
27
|
+
parent: LifecycleCommitBatch | null;
|
|
28
|
+
entries: LifecycleCommitBatchEntry[];
|
|
29
|
+
entriesByInstance: Map<ComponentInstance, LifecycleCommitBatchEntry>;
|
|
30
|
+
readCommits: ReadSubscriptionCommit[];
|
|
31
|
+
readCommitsByInstance: Map<ComponentInstance, ReadSubscriptionCommit>;
|
|
32
|
+
renderSnapshots: InlineRenderSnapshot[];
|
|
33
|
+
renderSnapshotsByInstance: Map<ComponentInstance, InlineRenderSnapshot>;
|
|
34
|
+
active: boolean;
|
|
35
|
+
};
|
|
36
|
+
declare function beginLifecycleCommitBatch(): LifecycleCommitBatch;
|
|
37
|
+
declare function captureInlineRenderSnapshot(instance: ComponentInstance): void;
|
|
38
|
+
declare function finalizeInlineReadSubscriptions(instance: ComponentInstance, token: number, pendingReadSources: Set<ReadableSource<unknown>> | undefined, pendingReadSourceVersions: Map<ReadableSource<unknown>, number> | undefined): void;
|
|
39
|
+
declare function flushLifecycleCommitBatch(batch: LifecycleCommitBatch): void;
|
|
40
|
+
declare function discardLifecycleCommitBatch(batch: LifecycleCommitBatch): void;
|
|
41
|
+
declare function registerMountOperationForInstance(instance: ComponentInstance | null, operation: LifecycleOperation): void;
|
|
42
|
+
declare function registerCommitOperationForInstance(instance: ComponentInstance | null, operation: LifecycleOperation): void;
|
|
43
|
+
declare function discardCommitOperations(instance: ComponentInstance): void;
|
|
44
|
+
declare function executeCommittedLifecycleOperations(instance: ComponentInstance, wasFirstMount: boolean): void;
|
|
45
|
+
declare function commitLifecycleForInstance(instance: ComponentInstance, wasFirstMount: boolean): void;
|
|
46
|
+
declare function commitRenderedComponent(instance: ComponentInstance): void;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { LifecycleCommitBatch, LifecycleOperation };
|
|
49
|
+
//# sourceMappingURL=component-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-lifecycle.d.ts","names":[],"sources":["../../src/runtime/component-lifecycle.ts"],"mappings":";;;;;;KAYY,kBAAA,+BAGR,WAAW;AAAA,KAEV,yBAAA;EACH,QAAA,EAAU,iBAAiB;EAC3B,aAAA;AAAA;AAAA,KAGG,sBAAA;EACH,QAAA,EAAU,iBAAA;EACV,KAAA;EACA,kBAAA,EAAoB,GAAA,CAAI,cAAA;EACxB,yBAAA,EAA2B,GAAA,CAAI,cAAA;AAAA;AAAA,KAG5B,oBAAA;EACH,QAAA,EAAU,iBAAA;EACV,KAAA,EAAO,KAAA;EACP,UAAA,EAAY,YAAA;EACZ,WAAA;EACA,cAAA,EAAgB,iBAAA;EAChB,MAAA;AAAA;AAAA,KAGU,oBAAA;EACV,MAAA,EAAQ,oBAAA;EACR,OAAA,EAAS,yBAAA;EACT,iBAAA,EAAmB,GAAA,CAAI,iBAAA,EAAmB,yBAAA;EAC1C,WAAA,EAAa,sBAAA;EACb,qBAAA,EAAuB,GAAA,CAAI,iBAAA,EAAmB,sBAAA;EAC9C,eAAA,EAAiB,oBAAA;EACjB,yBAAA,EAA2B,GAAA,CAAI,iBAAA,EAAmB,oBAAA;EAClD,MAAA;AAAA;AAAA,iBAKc,yBAAA,IAA6B,oBAAoB;AAAA,iBAkFjD,2BAAA,CAA4B,QAA2B,EAAjB,iBAAiB;AAAA,iBAevD,+BAAA,CACd,QAAA,EAAU,iBAAA,EACV,KAAA,UACA,kBAAA,EAAoB,GAAA,CAAI,cAAA,wBACxB,yBAAA,EAA2B,GAAA,CAAI,cAAA;AAAA,iBAqBjB,yBAAA,CAA0B,KAA2B,EAApB,oBAAoB;AAAA,iBAsCrD,2BAAA,CAA4B,KAA2B,EAApB,oBAAoB;AAAA,iBAsBvD,iCAAA,CACd,QAAA,EAAU,iBAAA,SACV,SAAA,EAAW,kBAAkB;AAAA,iBAkBf,kCAAA,CACd,QAAA,EAAU,iBAAA,SACV,SAAA,EAAW,kBAAkB;AAAA,iBA6Ef,uBAAA,CAAwB,QAA2B,EAAjB,iBAAiB;AAAA,iBAInD,mCAAA,CACd,QAAA,EAAU,iBAAiB,EAC3B,aAAA;AAAA,iBAUc,0BAAA,CACd,QAAA,EAAU,iBAAiB,EAC3B,aAAA;AAAA,iBAcc,uBAAA,CAAwB,QAA2B,EAAjB,iBAAiB"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { isDevelopmentEnvironment } from "../common/env.js";
|
|
2
|
+
import { logger } from "../dev/logger.js";
|
|
3
|
+
import { finalizeReadableSubscriptionsFromSnapshot } from "./readable.js";
|
|
4
|
+
import { isPromiseLike } from "../common/promise.js";
|
|
5
|
+
import { isBulkCommitActive } from "./fastlane.js";
|
|
6
|
+
//#region src/runtime/component-lifecycle.ts
|
|
7
|
+
let currentLifecycleCommitBatch = null;
|
|
8
|
+
function beginLifecycleCommitBatch() {
|
|
9
|
+
const batch = {
|
|
10
|
+
parent: currentLifecycleCommitBatch,
|
|
11
|
+
entries: [],
|
|
12
|
+
entriesByInstance: /* @__PURE__ */ new Map(),
|
|
13
|
+
readCommits: [],
|
|
14
|
+
readCommitsByInstance: /* @__PURE__ */ new Map(),
|
|
15
|
+
renderSnapshots: [],
|
|
16
|
+
renderSnapshotsByInstance: /* @__PURE__ */ new Map(),
|
|
17
|
+
active: true
|
|
18
|
+
};
|
|
19
|
+
currentLifecycleCommitBatch = batch;
|
|
20
|
+
return batch;
|
|
21
|
+
}
|
|
22
|
+
function closeLifecycleCommitBatch(batch) {
|
|
23
|
+
if (!batch.active) return false;
|
|
24
|
+
batch.active = false;
|
|
25
|
+
currentLifecycleCommitBatch = batch.parent;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
function enqueueLifecycleCommit(batch, instance, wasFirstMount) {
|
|
29
|
+
const existing = batch.entriesByInstance.get(instance);
|
|
30
|
+
if (existing) {
|
|
31
|
+
existing.wasFirstMount = existing.wasFirstMount || wasFirstMount;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const entry = {
|
|
35
|
+
instance,
|
|
36
|
+
wasFirstMount
|
|
37
|
+
};
|
|
38
|
+
batch.entriesByInstance.set(instance, entry);
|
|
39
|
+
batch.entries.push(entry);
|
|
40
|
+
}
|
|
41
|
+
function enqueueReadSubscriptionCommit(batch, instance, token, pendingReadSources, pendingReadSourceVersions) {
|
|
42
|
+
const existing = batch.readCommitsByInstance.get(instance);
|
|
43
|
+
const commit = existing ?? {
|
|
44
|
+
instance,
|
|
45
|
+
token,
|
|
46
|
+
pendingReadSources,
|
|
47
|
+
pendingReadSourceVersions
|
|
48
|
+
};
|
|
49
|
+
commit.token = token;
|
|
50
|
+
commit.pendingReadSources = pendingReadSources ? new Set(pendingReadSources) : void 0;
|
|
51
|
+
commit.pendingReadSourceVersions = pendingReadSourceVersions ? new Map(pendingReadSourceVersions) : void 0;
|
|
52
|
+
if (!existing) {
|
|
53
|
+
batch.readCommitsByInstance.set(instance, commit);
|
|
54
|
+
batch.readCommits.push(commit);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function enqueueInlineRenderSnapshot(batch, snapshot) {
|
|
58
|
+
if (batch.renderSnapshotsByInstance.has(snapshot.instance)) return;
|
|
59
|
+
batch.renderSnapshotsByInstance.set(snapshot.instance, snapshot);
|
|
60
|
+
batch.renderSnapshots.push(snapshot);
|
|
61
|
+
}
|
|
62
|
+
function captureInlineRenderSnapshot(instance) {
|
|
63
|
+
if (!currentLifecycleCommitBatch?.active) return;
|
|
64
|
+
enqueueInlineRenderSnapshot(currentLifecycleCommitBatch, {
|
|
65
|
+
instance,
|
|
66
|
+
props: instance.props,
|
|
67
|
+
ownerFrame: instance.ownerFrame,
|
|
68
|
+
portalScope: instance.portalScope,
|
|
69
|
+
parentInstance: instance.parentInstance,
|
|
70
|
+
isRoot: instance.isRoot
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function finalizeInlineReadSubscriptions(instance, token, pendingReadSources, pendingReadSourceVersions) {
|
|
74
|
+
if (currentLifecycleCommitBatch?.active) {
|
|
75
|
+
enqueueReadSubscriptionCommit(currentLifecycleCommitBatch, instance, token, pendingReadSources, pendingReadSourceVersions);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
finalizeReadableSubscriptionsFromSnapshot(instance, token, pendingReadSources, pendingReadSourceVersions);
|
|
79
|
+
}
|
|
80
|
+
function flushLifecycleCommitBatch(batch) {
|
|
81
|
+
if (!closeLifecycleCommitBatch(batch)) return;
|
|
82
|
+
if (batch.parent?.active) {
|
|
83
|
+
for (const snapshot of batch.renderSnapshots) enqueueInlineRenderSnapshot(batch.parent, snapshot);
|
|
84
|
+
for (const commit of batch.readCommits) enqueueReadSubscriptionCommit(batch.parent, commit.instance, commit.token, commit.pendingReadSources, commit.pendingReadSourceVersions);
|
|
85
|
+
for (const entry of batch.entries) enqueueLifecycleCommit(batch.parent, entry.instance, entry.wasFirstMount);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
for (const commit of batch.readCommits) finalizeReadableSubscriptionsFromSnapshot(commit.instance, commit.token, commit.pendingReadSources, commit.pendingReadSourceVersions);
|
|
89
|
+
for (const entry of batch.entries) executeCommittedLifecycleOperations(entry.instance, entry.wasFirstMount);
|
|
90
|
+
}
|
|
91
|
+
function discardLifecycleCommitBatch(batch) {
|
|
92
|
+
if (!closeLifecycleCommitBatch(batch)) return;
|
|
93
|
+
for (let index = batch.renderSnapshots.length - 1; index >= 0; index -= 1) {
|
|
94
|
+
const snapshot = batch.renderSnapshots[index];
|
|
95
|
+
snapshot.instance.props = snapshot.props;
|
|
96
|
+
snapshot.instance.ownerFrame = snapshot.ownerFrame;
|
|
97
|
+
snapshot.instance.portalScope = snapshot.portalScope;
|
|
98
|
+
snapshot.instance.parentInstance = snapshot.parentInstance;
|
|
99
|
+
snapshot.instance.isRoot = snapshot.isRoot;
|
|
100
|
+
}
|
|
101
|
+
for (const entry of batch.entries) {
|
|
102
|
+
if (entry.wasFirstMount) entry.instance.mountOperations = [];
|
|
103
|
+
discardCommitOperations(entry.instance);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function registerMountOperationForInstance(instance, operation) {
|
|
107
|
+
if (instance) {
|
|
108
|
+
if (isBulkCommitActive()) {
|
|
109
|
+
if (isDevelopmentEnvironment()) throw new Error("registerMountOperation called during bulk commit fast-lane");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
instance.mountOperations.push(operation);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function registerCommitOperationForInstance(instance, operation) {
|
|
116
|
+
if (instance) {
|
|
117
|
+
if (isBulkCommitActive()) {
|
|
118
|
+
if (isDevelopmentEnvironment()) throw new Error("registerCommitOperation called during bulk commit fast-lane");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
instance.commitOperations.push(operation);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function settleLifecycleOperationResult(instance, lifecycleGeneration, result) {
|
|
125
|
+
if (isPromiseLike(result)) Promise.resolve(result).then((cleanup) => {
|
|
126
|
+
if (typeof cleanup === "function") {
|
|
127
|
+
if (instance.lifecycleGeneration === lifecycleGeneration && instance.mounted) {
|
|
128
|
+
instance.cleanupFns.push(cleanup);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
cleanup();
|
|
133
|
+
} catch (err) {
|
|
134
|
+
logger.error("[Askr] async mount cleanup failed:", err);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}, (err) => {
|
|
138
|
+
logger.error("[Askr] async mount operation failed:", err);
|
|
139
|
+
});
|
|
140
|
+
else if (typeof result === "function") instance.cleanupFns.push(result);
|
|
141
|
+
}
|
|
142
|
+
function executeMountOperations(instance) {
|
|
143
|
+
const mountOperations = instance.mountOperations;
|
|
144
|
+
if (mountOperations.length === 0) return;
|
|
145
|
+
const lifecycleGeneration = instance.lifecycleGeneration;
|
|
146
|
+
for (const operation of mountOperations) settleLifecycleOperationResult(instance, lifecycleGeneration, operation());
|
|
147
|
+
instance.mountOperations = [];
|
|
148
|
+
}
|
|
149
|
+
function executeCommitOperations(instance) {
|
|
150
|
+
const commitOperations = instance.commitOperations;
|
|
151
|
+
if (commitOperations.length === 0) return;
|
|
152
|
+
instance.commitOperations = [];
|
|
153
|
+
const lifecycleGeneration = instance.lifecycleGeneration;
|
|
154
|
+
for (const operation of commitOperations) settleLifecycleOperationResult(instance, lifecycleGeneration, operation());
|
|
155
|
+
}
|
|
156
|
+
function discardCommitOperations(instance) {
|
|
157
|
+
instance.commitOperations = [];
|
|
158
|
+
}
|
|
159
|
+
function executeCommittedLifecycleOperations(instance, wasFirstMount) {
|
|
160
|
+
if (wasFirstMount && instance.mountOperations.length > 0) executeMountOperations(instance);
|
|
161
|
+
if (instance.commitOperations.length > 0) executeCommitOperations(instance);
|
|
162
|
+
}
|
|
163
|
+
function commitLifecycleForInstance(instance, wasFirstMount) {
|
|
164
|
+
if (currentLifecycleCommitBatch) {
|
|
165
|
+
enqueueLifecycleCommit(currentLifecycleCommitBatch, instance, wasFirstMount);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
executeCommittedLifecycleOperations(instance, wasFirstMount);
|
|
169
|
+
}
|
|
170
|
+
function commitRenderedComponent(instance) {
|
|
171
|
+
if (instance.mounted && instance.commitOperations.length > 0) commitLifecycleForInstance(instance, false);
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { beginLifecycleCommitBatch, captureInlineRenderSnapshot, commitLifecycleForInstance, commitRenderedComponent, discardCommitOperations, discardLifecycleCommitBatch, executeCommittedLifecycleOperations, finalizeInlineReadSubscriptions, flushLifecycleCommitBatch, registerCommitOperationForInstance, registerMountOperationForInstance };
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=component-lifecycle.js.map
|