aktion-runtime 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/dist/aktion.iife.js +19 -19
- package/dist/aktion.iife.js.map +1 -1
- package/dist/aktion.js +214 -187
- package/dist/aktion.js.map +1 -1
- package/dist/aktion.umd.cjs +19 -19
- package/dist/aktion.umd.cjs.map +1 -1
- package/dist/types/renderer/renderer.d.ts +7 -3
- package/dist/types/runtime/effects.d.ts +2 -2
- package/dist/types/runtime/evaluator.d.ts +25 -3
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { EvaluationContext } from '../runtime/evaluator.js';
|
|
2
|
-
import { EffectDeclaration } from '../parser/types.js';
|
|
1
|
+
import { EvaluationContext, ScopedEffectDecl } from '../runtime/evaluator.js';
|
|
3
2
|
import { StateStore } from '../runtime/state.js';
|
|
4
3
|
import { Router } from '../runtime/router.js';
|
|
5
4
|
import { ComponentLibrary } from '../library/types.js';
|
|
@@ -25,8 +24,13 @@ export interface RenderOptions {
|
|
|
25
24
|
* the instance; the implementation is expected to be idempotent so
|
|
26
25
|
* re-renders are no-ops once the effects are mounted. The host wires
|
|
27
26
|
* this to the same `EffectRunner` that handles top-level effects.
|
|
27
|
+
*
|
|
28
|
+
* Each entry pairs the declaration with the per-instance alias frames
|
|
29
|
+
* captured when the body was walked, so writes inside the effect body
|
|
30
|
+
* resolve to the same per-instance state slots the component itself
|
|
31
|
+
* uses.
|
|
28
32
|
*/
|
|
29
|
-
mountInstanceEffects?: (instanceKey: string, decls: ReadonlyArray<
|
|
33
|
+
mountInstanceEffects?: (instanceKey: string, decls: ReadonlyArray<ScopedEffectDecl>, getCtx: () => EvaluationContext) => void;
|
|
30
34
|
/**
|
|
31
35
|
* Tear down every per-instance effect mounted under `instanceKey`.
|
|
32
36
|
* Invoked when the component instance disappears from the render tree
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ActionDeclaration, EffectDeclaration } from '../parser/types.js';
|
|
2
|
-
import { EvaluationContext } from './evaluator.js';
|
|
2
|
+
import { EvaluationContext, ScopedEffectDecl } from './evaluator.js';
|
|
3
3
|
import { StateStore } from './state.js';
|
|
4
4
|
export interface EffectRunnerOptions {
|
|
5
5
|
state: StateStore;
|
|
@@ -40,7 +40,7 @@ export declare class EffectRunner {
|
|
|
40
40
|
* a no-op; effects that vanished from the body since the last render are
|
|
41
41
|
* torn down. Effects belonging to other instances are untouched.
|
|
42
42
|
*/
|
|
43
|
-
syncInstanceEffects(instanceKey: string, decls: ReadonlyArray<
|
|
43
|
+
syncInstanceEffects(instanceKey: string, decls: ReadonlyArray<ScopedEffectDecl>, getCtx: () => EvaluationContext): void;
|
|
44
44
|
/**
|
|
45
45
|
* Tear down every effect that belongs to the given component instance
|
|
46
46
|
* (i.e. mounted via `syncInstanceEffects(instanceKey, …)`). Called by
|
|
@@ -55,6 +55,22 @@ export interface UserComponentNode {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
export declare const isUserComponentNode: (value: unknown) => value is UserComponentNode;
|
|
58
|
+
/**
|
|
59
|
+
* An `effect [ … ] { … }` declaration discovered inside a `component { … }`
|
|
60
|
+
* body, paired with the per-instance state-alias stack captured at the
|
|
61
|
+
* moment the body was walked. The runner restores those aliases before
|
|
62
|
+
* running the body so `$count = …` lands on the same instance slot the
|
|
63
|
+
* component itself uses, even though the alias frame is no longer on
|
|
64
|
+
* `ctx.stateAliases` by the time the effect fires.
|
|
65
|
+
*/
|
|
66
|
+
export interface ScopedEffectDecl {
|
|
67
|
+
decl: EffectDeclaration;
|
|
68
|
+
/**
|
|
69
|
+
* Cloned alias frames in stack order (bottom → top). `[]` for effects
|
|
70
|
+
* declared at the program top level, where no per-instance frame applies.
|
|
71
|
+
*/
|
|
72
|
+
capturedAliases: ReadonlyArray<ReadonlyMap<string, string>>;
|
|
73
|
+
}
|
|
58
74
|
export interface EvaluationContext {
|
|
59
75
|
state: StateStore;
|
|
60
76
|
/** Per-program scope for non-state assignments (refs to other lines). */
|
|
@@ -94,8 +110,13 @@ export interface EvaluationContext {
|
|
|
94
110
|
* immediately after `evaluateUserComponent` returns so it can mount the
|
|
95
111
|
* declarations on a per-instance scope (instead of globally, once per
|
|
96
112
|
* program).
|
|
113
|
+
*
|
|
114
|
+
* Each entry pairs the declaration with a snapshot of `stateAliases` at
|
|
115
|
+
* the moment the body was walked, so `$x = …` writes inside the effect
|
|
116
|
+
* body resolve through the per-instance alias frame even after the
|
|
117
|
+
* component body has returned and the alias frame has been popped.
|
|
97
118
|
*/
|
|
98
|
-
componentEffectStack:
|
|
119
|
+
componentEffectStack: ScopedEffectDecl[][];
|
|
99
120
|
/** Action declarations (`action Foo() { ... }`). */
|
|
100
121
|
actionDecls: Map<string, ActionDeclaration>;
|
|
101
122
|
/** HTTP runtime (`http({...})` calls + interceptor configuration). */
|
|
@@ -150,13 +171,14 @@ export declare function evaluate(expr: Expression, ctx: EvaluationContext): unkn
|
|
|
150
171
|
* Result of `evaluateUserComponent`. `value` is the body's last
|
|
151
172
|
* expression value (a `ComponentNode`, another `UserComponentNode`, or a
|
|
152
173
|
* primitive) that the renderer will materialise. `effects` is the list of
|
|
153
|
-
* `effect [ ...deps ] { … }` declarations discovered inside the body
|
|
174
|
+
* `effect [ ...deps ] { … }` declarations discovered inside the body
|
|
175
|
+
* (paired with the per-instance alias stack captured at walk time) —
|
|
154
176
|
* the renderer hands them to the host's `EffectRunner` so they mount on
|
|
155
177
|
* a per-instance scope and tear down when the instance unmounts.
|
|
156
178
|
*/
|
|
157
179
|
export interface EvaluatedUserComponent {
|
|
158
180
|
value: unknown;
|
|
159
|
-
effects: ReadonlyArray<
|
|
181
|
+
effects: ReadonlyArray<ScopedEffectDecl>;
|
|
160
182
|
}
|
|
161
183
|
/**
|
|
162
184
|
* Evaluate a user-declared component body in a fresh per-instance scope.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aktion-runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Aktion is a single web component that turns a compact, streaming-first DSL into a rich, interactive UI inside its shadow DOM. Works in React, Vue, Angular, Svelte, plain HTML — or no framework at all.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|