@constela/runtime 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +103 -0
  2. package/package.json +3 -3
@@ -0,0 +1,103 @@
1
+ import { CompiledExpression, CompiledAction, CompiledNode, CompiledProgram } from '@constela/compiler';
2
+
3
+ interface Signal<T> {
4
+ get(): T;
5
+ set(value: T): void;
6
+ subscribe?(fn: (value: T) => void): () => void;
7
+ }
8
+ declare function createSignal<T>(initial: T): Signal<T>;
9
+
10
+ /**
11
+ * Effect - Reactive side effect
12
+ *
13
+ * An effect runs a function and automatically tracks signal dependencies.
14
+ * When any tracked signal changes, the effect re-runs.
15
+ */
16
+ type CleanupFn = () => void;
17
+ type EffectFn = () => void | CleanupFn;
18
+ declare function createEffect(fn: EffectFn): () => void;
19
+
20
+ /**
21
+ * StateStore - Centralized state management
22
+ *
23
+ * Creates signals for each state field defined in the program.
24
+ * Provides get/set methods for accessing state.
25
+ */
26
+ interface StateStore {
27
+ get(name: string): unknown;
28
+ set(name: string, value: unknown): void;
29
+ }
30
+ interface StateDefinition {
31
+ type: string;
32
+ initial: unknown;
33
+ }
34
+ declare function createStateStore(definitions: Record<string, StateDefinition>): StateStore;
35
+
36
+ /**
37
+ * Expression Evaluator - Evaluates compiled expressions
38
+ *
39
+ * Supports:
40
+ * - Literal values (lit)
41
+ * - State reads (state)
42
+ * - Variable reads (var)
43
+ * - Binary operations (bin)
44
+ * - Not operation (not)
45
+ * - Conditional expressions (cond)
46
+ * - Property access (get)
47
+ */
48
+
49
+ interface EvaluationContext {
50
+ state: StateStore;
51
+ locals: Record<string, unknown>;
52
+ }
53
+ declare function evaluate(expr: CompiledExpression, ctx: EvaluationContext): unknown;
54
+
55
+ /**
56
+ * Action Executor - Executes compiled action steps
57
+ *
58
+ * Supports:
59
+ * - set: Update state with value
60
+ * - update: Increment/decrement numbers, push/pop/remove for arrays
61
+ * - fetch: Make HTTP requests with onSuccess/onError handlers
62
+ */
63
+
64
+ interface ActionContext {
65
+ state: StateStore;
66
+ actions: Record<string, CompiledAction>;
67
+ locals: Record<string, unknown>;
68
+ eventPayload?: unknown;
69
+ }
70
+ declare function executeAction(action: CompiledAction, ctx: ActionContext): Promise<void>;
71
+
72
+ /**
73
+ * Renderer - DOM rendering for compiled view nodes
74
+ *
75
+ * Renders:
76
+ * - element: Creates DOM elements with props and event handlers
77
+ * - text: Creates text nodes
78
+ * - if: Conditional rendering with reactive updates
79
+ * - each: List rendering with reactive updates
80
+ */
81
+
82
+ interface RenderContext {
83
+ state: StateStore;
84
+ actions: Record<string, CompiledAction>;
85
+ locals: Record<string, unknown>;
86
+ cleanups?: (() => void)[];
87
+ }
88
+ declare function render(node: CompiledNode, ctx: RenderContext): Node;
89
+
90
+ /**
91
+ * App - Main entry point for creating Constela applications
92
+ *
93
+ * Creates a reactive application from a CompiledProgram and mounts it to the DOM.
94
+ */
95
+
96
+ interface AppInstance {
97
+ destroy(): void;
98
+ setState(name: string, value: unknown): void;
99
+ getState(name: string): unknown;
100
+ }
101
+ declare function createApp(program: CompiledProgram, mount: HTMLElement): AppInstance;
102
+
103
+ export { type ActionContext, type AppInstance, type EvaluationContext, type RenderContext, type Signal, type StateStore, createApp, createEffect, createSignal, createStateStore, evaluate, executeAction, render };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/runtime",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Runtime DOM renderer for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,8 +15,8 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@constela/core": "0.3.0",
19
- "@constela/compiler": "0.3.0"
18
+ "@constela/core": "0.3.1",
19
+ "@constela/compiler": "0.3.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^20.10.0",