@elaraai/east-ui 0.0.1-beta.21 → 0.0.1-beta.23
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/src/index.d.ts +1 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/platform/index.d.ts +20 -195
- package/dist/src/platform/index.d.ts.map +1 -1
- package/dist/src/platform/index.js +20 -197
- package/dist/src/platform/index.js.map +1 -1
- package/dist/src/platform/state.d.ts +22 -177
- package/dist/src/platform/state.d.ts.map +1 -1
- package/dist/src/platform/state.js +22 -260
- package/dist/src/platform/state.js.map +1 -1
- package/dist/src/reactive/index.d.ts +2 -2
- package/dist/src/reactive/index.d.ts.map +1 -1
- package/dist/src/reactive/index.js +2 -18
- package/dist/src/reactive/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/src/platform/store.d.ts +0 -172
- package/dist/src/platform/store.d.ts.map +0 -1
- package/dist/src/platform/store.js +0 -246
- package/dist/src/platform/store.js.map +0 -1
|
@@ -3,201 +3,46 @@
|
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* State management platform
|
|
6
|
+
* State management platform function signatures.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This module contains only platform function definitions created with `East.platform()`.
|
|
10
|
+
* All runtime implementations are in `@elaraai/east-ui-components`.
|
|
10
11
|
*
|
|
11
12
|
* @packageDocumentation
|
|
12
13
|
*/
|
|
13
|
-
import { StringType,
|
|
14
|
-
import { type PlatformFunction, OptionType } from "@elaraai/east/internal";
|
|
15
|
-
import { UIStore } from "./store.js";
|
|
14
|
+
import { StringType, NullType, BooleanType } from "@elaraai/east";
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @remarks
|
|
20
|
-
* Call this before executing a reactive component's render function.
|
|
21
|
-
* All subsequent `state_read` calls will record their keys to the tracking set.
|
|
22
|
-
* Call {@link disableTracking} when done to get the collected keys.
|
|
16
|
+
* Reads a Beast2-encoded value from state storage.
|
|
23
17
|
*
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* enableTracking();
|
|
29
|
-
* try {
|
|
30
|
-
* const result = renderFn();
|
|
31
|
-
* const deps = disableTracking();
|
|
32
|
-
* // deps contains all state keys read during renderFn()
|
|
33
|
-
* } catch (e) {
|
|
34
|
-
* disableTracking();
|
|
35
|
-
* throw e;
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function enableTracking(): Set<string>;
|
|
40
|
-
/**
|
|
41
|
-
* Disable dependency tracking and return collected keys.
|
|
18
|
+
* @param key - The state key to read from
|
|
19
|
+
* @returns Option of Beast2-encoded blob (some if exists, none if not found)
|
|
42
20
|
*
|
|
43
21
|
* @remarks
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @returns Array of state keys that were read during tracking
|
|
22
|
+
* Returns `none` if the key does not exist, `some(blob)` if it does.
|
|
23
|
+
* Implementation provided by `StateImpl` in `@elaraai/east-ui-components`.
|
|
48
24
|
*/
|
|
49
|
-
export declare
|
|
25
|
+
export declare const state_read: import("@elaraai/east").GenericPlatformDefinition<readonly ["T"], readonly [StringType], "T">;
|
|
50
26
|
/**
|
|
51
|
-
*
|
|
27
|
+
* Writes a Beast2-encoded value to state storage.
|
|
52
28
|
*
|
|
53
|
-
* @
|
|
54
|
-
|
|
55
|
-
export declare function isTracking(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Record a key access during dependency tracking.
|
|
58
|
-
*
|
|
59
|
-
* @remarks
|
|
60
|
-
* Called internally by the `state_read` implementation.
|
|
61
|
-
* Only records if tracking is enabled via {@link enableTracking}.
|
|
62
|
-
*
|
|
63
|
-
* @param key - The state key being accessed
|
|
64
|
-
*/
|
|
65
|
-
export declare function trackKey(key: string): void;
|
|
66
|
-
/**
|
|
67
|
-
* Platform function to write a Beast2-encoded value to the state store.
|
|
68
|
-
*
|
|
69
|
-
* @remarks
|
|
70
|
-
* Writes a blob to state, or deletes the key if `none` is passed.
|
|
71
|
-
* Triggers re-render in reactive contexts.
|
|
72
|
-
*
|
|
73
|
-
* @param key - The string key to write to
|
|
74
|
-
* @param value - The Beast2-encoded blob value (some to write, none to delete)
|
|
29
|
+
* @param key - The state key to write to
|
|
30
|
+
* @param value - The value to write (some to set, none to delete)
|
|
75
31
|
* @returns Null
|
|
76
|
-
*/
|
|
77
|
-
export declare const state_write: import("@elaraai/east").PlatformDefinition<[StringType, OptionType<BlobType>], NullType>;
|
|
78
|
-
/**
|
|
79
|
-
* Platform function to read a Beast2-encoded value from the state store.
|
|
80
|
-
*
|
|
81
|
-
* @remarks
|
|
82
|
-
* Returns `some(blob)` if the key exists, `none` if not.
|
|
83
|
-
* Use `.match()` to handle both cases.
|
|
84
|
-
*
|
|
85
|
-
* @param key - The string key to read from
|
|
86
|
-
* @returns Option of Beast2-encoded blob (some if exists, none if not)
|
|
87
|
-
*/
|
|
88
|
-
export declare const state_read: import("@elaraai/east").PlatformDefinition<[StringType], OptionType<BlobType>>;
|
|
89
|
-
/**
|
|
90
|
-
* Platform function to check if a key exists in the state store.
|
|
91
|
-
*
|
|
92
|
-
* @remarks
|
|
93
|
-
* Returns true if the key exists, false otherwise.
|
|
94
|
-
*
|
|
95
|
-
* @param key - The string key to check
|
|
96
|
-
* @returns Boolean indicating existence of the key
|
|
97
|
-
*/
|
|
98
|
-
export declare const state_has: import("@elaraai/east").PlatformDefinition<[StringType], BooleanType>;
|
|
99
|
-
/**
|
|
100
|
-
* Singleton UI store instance for state management.
|
|
101
32
|
*
|
|
102
33
|
* @remarks
|
|
103
|
-
*
|
|
104
|
-
*
|
|
34
|
+
* Pass `none` to delete the key from state.
|
|
35
|
+
* Implementation provided by `StateImpl` in `@elaraai/east-ui-components`.
|
|
105
36
|
*/
|
|
106
|
-
export declare const
|
|
37
|
+
export declare const state_write: import("@elaraai/east").GenericPlatformDefinition<readonly ["T"], readonly [StringType, "T"], NullType>;
|
|
107
38
|
/**
|
|
108
|
-
*
|
|
39
|
+
* Checks if a key exists in state storage.
|
|
109
40
|
*
|
|
110
|
-
* @
|
|
111
|
-
*
|
|
112
|
-
* bound to the singleton {@link store}. Pass this to `ir.compile()` to enable
|
|
113
|
-
* state functionality.
|
|
114
|
-
*/
|
|
115
|
-
export declare const StateImpl: PlatformFunction[];
|
|
116
|
-
/**
|
|
117
|
-
* Creates a typed state write function for a given key and type.
|
|
41
|
+
* @param key - The state key to check
|
|
42
|
+
* @returns Boolean indicating whether the key exists
|
|
118
43
|
*
|
|
119
44
|
* @remarks
|
|
120
|
-
*
|
|
121
|
-
* automatically Beast2-encoded before storage. Pass `some(value)` to write
|
|
122
|
-
* or `none` to delete the key.
|
|
123
|
-
*
|
|
124
|
-
* @typeParam T - The East type of the value to write
|
|
125
|
-
* @param key - The string key to write to
|
|
126
|
-
* @param value - The value wrapped in an option (some to write, none to delete)
|
|
127
|
-
* @param type - The East type descriptor for the value
|
|
128
|
-
* @returns A callable East function that performs the write
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* import { East, IntegerType, NullType, some } from "@elaraai/east";
|
|
133
|
-
* import { State, UIComponentType } from "@elaraai/east-ui";
|
|
134
|
-
*
|
|
135
|
-
* const counter = East.function([], UIComponentType, $ => {
|
|
136
|
-
* // Write 42 to "counter" key
|
|
137
|
-
* $(State.writeTyped("counter", some(42n), IntegerType)());
|
|
138
|
-
*
|
|
139
|
-
* // Delete the key
|
|
140
|
-
* $(State.writeTyped("counter", none, IntegerType)());
|
|
141
|
-
* });
|
|
142
|
-
* ```
|
|
45
|
+
* Implementation provided by `StateImpl` in `@elaraai/east-ui-components`.
|
|
143
46
|
*/
|
|
144
|
-
export declare const
|
|
145
|
-
/**
|
|
146
|
-
* Creates a typed state read function for a given key and type.
|
|
147
|
-
*
|
|
148
|
-
* @remarks
|
|
149
|
-
* Returns an East function that reads a typed value from state. The value is
|
|
150
|
-
* automatically Beast2-decoded after retrieval. Returns `some(value)` if the
|
|
151
|
-
* key exists, `none` if not.
|
|
152
|
-
*
|
|
153
|
-
* @typeParam T - The East type of the value to read
|
|
154
|
-
* @param key - The string key to read from
|
|
155
|
-
* @param type - The East type descriptor for the value
|
|
156
|
-
* @returns A callable East function that returns an option of the typed value
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* import { East, IntegerType, NullType } from "@elaraai/east";
|
|
161
|
-
* import { State, UIComponentType, Text } from "@elaraai/east-ui";
|
|
162
|
-
*
|
|
163
|
-
* const display = East.function([], UIComponentType, $ => {
|
|
164
|
-
* // Read typed value from state
|
|
165
|
-
* const count = $.let(State.readTyped("counter", IntegerType)());
|
|
166
|
-
*
|
|
167
|
-
* // Use the value (unwrap if you know it exists)
|
|
168
|
-
* return Text.Root(East.str`Count: ${count.unwrap("some")}`);
|
|
169
|
-
* });
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
export declare const state_read_typed: <T extends EastType>(key: SubtypeExprOrValue<StringType>, type: T) => CallableFunctionExpr<[], OptionType<T>>;
|
|
173
|
-
/**
|
|
174
|
-
* Creates a typed state initialization function that only writes if the key doesn't exist.
|
|
175
|
-
*
|
|
176
|
-
* @remarks
|
|
177
|
-
* Returns an East function that initializes a state key with a default value.
|
|
178
|
-
* The write only occurs if the key is not already set, preventing overwrites
|
|
179
|
-
* on re-renders. Use this for setting up initial state in components.
|
|
180
|
-
*
|
|
181
|
-
* @typeParam T - The East type of the value to initialize
|
|
182
|
-
* @param key - The string key to initialize
|
|
183
|
-
* @param value - The default value to write (not wrapped in option)
|
|
184
|
-
* @param type - The East type descriptor for the value
|
|
185
|
-
* @returns A callable East function that performs the conditional initialization
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```ts
|
|
189
|
-
* import { East, IntegerType } from "@elaraai/east";
|
|
190
|
-
* import { State, UIComponentType, Button } from "@elaraai/east-ui";
|
|
191
|
-
*
|
|
192
|
-
* const counter = East.function([], UIComponentType, $ => {
|
|
193
|
-
* // Initialize to 0 only if not already set
|
|
194
|
-
* $(State.initTyped("counter", 0n, IntegerType)());
|
|
195
|
-
*
|
|
196
|
-
* // Read and display
|
|
197
|
-
* const count = $.let(State.readTyped("counter", IntegerType)());
|
|
198
|
-
* // ...
|
|
199
|
-
* });
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
export declare const state_init_typed: <T extends EastType>(key: SubtypeExprOrValue<StringType>, value: SubtypeExprOrValue<T>, type: T) => CallableFunctionExpr<[], NullType>;
|
|
47
|
+
export declare const state_has: import("@elaraai/east").PlatformDefinition<[StringType], BooleanType>;
|
|
203
48
|
//# sourceMappingURL=state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/platform/state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/platform/state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAQ,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAExE;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,+FAKtB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,yGAKvB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,uEAAwD,CAAC"}
|
|
@@ -3,284 +3,46 @@
|
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* State management platform
|
|
7
|
-
*
|
|
8
|
-
* Provides reactive state operations for East UI programs.
|
|
9
|
-
* State is stored as Beast2-encoded blobs, allowing any East type to be stored.
|
|
10
|
-
*
|
|
11
|
-
* @packageDocumentation
|
|
12
|
-
*/
|
|
13
|
-
import { East, StringType, BlobType, NullType, none, some, BooleanType, } from "@elaraai/east";
|
|
14
|
-
import { OptionType } from "@elaraai/east/internal";
|
|
15
|
-
import { UIStore } from "./store.js";
|
|
16
|
-
// =============================================================================
|
|
17
|
-
// Reactive Dependency Tracking
|
|
18
|
-
// =============================================================================
|
|
19
|
-
/**
|
|
20
|
-
* Tracking context for reactive dependency collection.
|
|
21
|
-
* When set, state_read calls will record their keys here.
|
|
22
|
-
*/
|
|
23
|
-
let trackingContext = null;
|
|
24
|
-
/**
|
|
25
|
-
* Enable dependency tracking for reactive components.
|
|
6
|
+
* State management platform function signatures.
|
|
26
7
|
*
|
|
27
8
|
* @remarks
|
|
28
|
-
*
|
|
29
|
-
* All
|
|
30
|
-
* Call {@link disableTracking} when done to get the collected keys.
|
|
9
|
+
* This module contains only platform function definitions created with `East.platform()`.
|
|
10
|
+
* All runtime implementations are in `@elaraai/east-ui-components`.
|
|
31
11
|
*
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* enableTracking();
|
|
37
|
-
* try {
|
|
38
|
-
* const result = renderFn();
|
|
39
|
-
* const deps = disableTracking();
|
|
40
|
-
* // deps contains all state keys read during renderFn()
|
|
41
|
-
* } catch (e) {
|
|
42
|
-
* disableTracking();
|
|
43
|
-
* throw e;
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export function enableTracking() {
|
|
48
|
-
trackingContext = new Set();
|
|
49
|
-
return trackingContext;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Disable dependency tracking and return collected keys.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* Call this after executing a reactive component's render function.
|
|
56
|
-
* Returns all keys that were accessed via `state_read` since {@link enableTracking} was called.
|
|
57
|
-
*
|
|
58
|
-
* @returns Array of state keys that were read during tracking
|
|
12
|
+
* @packageDocumentation
|
|
59
13
|
*/
|
|
60
|
-
|
|
61
|
-
const keys = trackingContext ? [...trackingContext] : [];
|
|
62
|
-
trackingContext = null;
|
|
63
|
-
return keys;
|
|
64
|
-
}
|
|
14
|
+
import { East, StringType, NullType, BooleanType } from "@elaraai/east";
|
|
65
15
|
/**
|
|
66
|
-
*
|
|
16
|
+
* Reads a Beast2-encoded value from state storage.
|
|
67
17
|
*
|
|
68
|
-
* @
|
|
69
|
-
|
|
70
|
-
export function isTracking() {
|
|
71
|
-
return trackingContext !== null;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Record a key access during dependency tracking.
|
|
18
|
+
* @param key - The state key to read from
|
|
19
|
+
* @returns Option of Beast2-encoded blob (some if exists, none if not found)
|
|
75
20
|
*
|
|
76
21
|
* @remarks
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param key - The state key being accessed
|
|
22
|
+
* Returns `none` if the key does not exist, `some(blob)` if it does.
|
|
23
|
+
* Implementation provided by `StateImpl` in `@elaraai/east-ui-components`.
|
|
81
24
|
*/
|
|
82
|
-
export
|
|
83
|
-
if (trackingContext) {
|
|
84
|
-
trackingContext.add(key);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// =============================================================================
|
|
88
|
-
// Platform Functions
|
|
89
|
-
// =============================================================================
|
|
25
|
+
export const state_read = East.genericPlatform("state_read", ["T"], [StringType], "T");
|
|
90
26
|
/**
|
|
91
|
-
*
|
|
27
|
+
* Writes a Beast2-encoded value to state storage.
|
|
92
28
|
*
|
|
93
|
-
* @
|
|
94
|
-
*
|
|
95
|
-
* Triggers re-render in reactive contexts.
|
|
96
|
-
*
|
|
97
|
-
* @param key - The string key to write to
|
|
98
|
-
* @param value - The Beast2-encoded blob value (some to write, none to delete)
|
|
29
|
+
* @param key - The state key to write to
|
|
30
|
+
* @param value - The value to write (some to set, none to delete)
|
|
99
31
|
* @returns Null
|
|
100
|
-
*/
|
|
101
|
-
export const state_write = East.platform("state_write", [StringType, OptionType(BlobType)], NullType);
|
|
102
|
-
/**
|
|
103
|
-
* Platform function to read a Beast2-encoded value from the state store.
|
|
104
|
-
*
|
|
105
|
-
* @remarks
|
|
106
|
-
* Returns `some(blob)` if the key exists, `none` if not.
|
|
107
|
-
* Use `.match()` to handle both cases.
|
|
108
|
-
*
|
|
109
|
-
* @param key - The string key to read from
|
|
110
|
-
* @returns Option of Beast2-encoded blob (some if exists, none if not)
|
|
111
|
-
*/
|
|
112
|
-
export const state_read = East.platform("state_read", [StringType], OptionType(BlobType));
|
|
113
|
-
/**
|
|
114
|
-
* Platform function to check if a key exists in the state store.
|
|
115
|
-
*
|
|
116
|
-
* @remarks
|
|
117
|
-
* Returns true if the key exists, false otherwise.
|
|
118
|
-
*
|
|
119
|
-
* @param key - The string key to check
|
|
120
|
-
* @returns Boolean indicating existence of the key
|
|
121
|
-
*/
|
|
122
|
-
export const state_has = East.platform("state_has", [StringType], BooleanType);
|
|
123
|
-
/**
|
|
124
|
-
* Singleton UI store instance for state management.
|
|
125
|
-
*
|
|
126
|
-
* @remarks
|
|
127
|
-
* This is the global store used by {@link StateImpl}. Access directly
|
|
128
|
-
* for React integration, subscriptions, or debugging.
|
|
129
|
-
*/
|
|
130
|
-
export const store = new UIStore();
|
|
131
|
-
/**
|
|
132
|
-
* Platform implementation for state management operations.
|
|
133
32
|
*
|
|
134
33
|
* @remarks
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* state functionality.
|
|
138
|
-
*/
|
|
139
|
-
export const StateImpl = [
|
|
140
|
-
state_write.implement((key, value) => {
|
|
141
|
-
if (value.type === 'none') {
|
|
142
|
-
store.write(key, undefined);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
store.write(key, value.value);
|
|
146
|
-
}
|
|
147
|
-
}),
|
|
148
|
-
state_read.implement((key) => {
|
|
149
|
-
// Track the key if in tracking mode (for reactive dependency collection)
|
|
150
|
-
trackKey(key);
|
|
151
|
-
const ret = store.read(key);
|
|
152
|
-
if (ret === undefined) {
|
|
153
|
-
return none;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
return some(ret);
|
|
157
|
-
}
|
|
158
|
-
}),
|
|
159
|
-
state_has.implement((key) => {
|
|
160
|
-
return store.has(key);
|
|
161
|
-
}),
|
|
162
|
-
];
|
|
163
|
-
/**
|
|
164
|
-
* Creates a typed state write function for a given key and type.
|
|
165
|
-
*
|
|
166
|
-
* @remarks
|
|
167
|
-
* Returns an East function that writes a typed value to state. The value is
|
|
168
|
-
* automatically Beast2-encoded before storage. Pass `some(value)` to write
|
|
169
|
-
* or `none` to delete the key.
|
|
170
|
-
*
|
|
171
|
-
* @typeParam T - The East type of the value to write
|
|
172
|
-
* @param key - The string key to write to
|
|
173
|
-
* @param value - The value wrapped in an option (some to write, none to delete)
|
|
174
|
-
* @param type - The East type descriptor for the value
|
|
175
|
-
* @returns A callable East function that performs the write
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```ts
|
|
179
|
-
* import { East, IntegerType, NullType, some } from "@elaraai/east";
|
|
180
|
-
* import { State, UIComponentType } from "@elaraai/east-ui";
|
|
181
|
-
*
|
|
182
|
-
* const counter = East.function([], UIComponentType, $ => {
|
|
183
|
-
* // Write 42 to "counter" key
|
|
184
|
-
* $(State.writeTyped("counter", some(42n), IntegerType)());
|
|
185
|
-
*
|
|
186
|
-
* // Delete the key
|
|
187
|
-
* $(State.writeTyped("counter", none, IntegerType)());
|
|
188
|
-
* });
|
|
189
|
-
* ```
|
|
34
|
+
* Pass `none` to delete the key from state.
|
|
35
|
+
* Implementation provided by `StateImpl` in `@elaraai/east-ui-components`.
|
|
190
36
|
*/
|
|
191
|
-
export const
|
|
192
|
-
return East.function([], NullType, $ => {
|
|
193
|
-
const key_expr = East.value(key);
|
|
194
|
-
const value_expr = East.value(value, OptionType(type));
|
|
195
|
-
$.match(value_expr, {
|
|
196
|
-
some: ($, v) => {
|
|
197
|
-
$(state_write(key_expr, some(East.Blob.encodeBeast(v, "v2"))));
|
|
198
|
-
},
|
|
199
|
-
none: ($) => {
|
|
200
|
-
$(state_write(key_expr, none));
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
return null;
|
|
204
|
-
});
|
|
205
|
-
};
|
|
37
|
+
export const state_write = East.genericPlatform("state_write", ["T"], [StringType, "T"], NullType);
|
|
206
38
|
/**
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* @remarks
|
|
210
|
-
* Returns an East function that reads a typed value from state. The value is
|
|
211
|
-
* automatically Beast2-decoded after retrieval. Returns `some(value)` if the
|
|
212
|
-
* key exists, `none` if not.
|
|
213
|
-
*
|
|
214
|
-
* @typeParam T - The East type of the value to read
|
|
215
|
-
* @param key - The string key to read from
|
|
216
|
-
* @param type - The East type descriptor for the value
|
|
217
|
-
* @returns A callable East function that returns an option of the typed value
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```ts
|
|
221
|
-
* import { East, IntegerType, NullType } from "@elaraai/east";
|
|
222
|
-
* import { State, UIComponentType, Text } from "@elaraai/east-ui";
|
|
223
|
-
*
|
|
224
|
-
* const display = East.function([], UIComponentType, $ => {
|
|
225
|
-
* // Read typed value from state
|
|
226
|
-
* const count = $.let(State.readTyped("counter", IntegerType)());
|
|
39
|
+
* Checks if a key exists in state storage.
|
|
227
40
|
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* });
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
export const state_read_typed = (key, type) => {
|
|
234
|
-
return East.function([], OptionType(type), $ => {
|
|
235
|
-
const key_expr = East.value(key);
|
|
236
|
-
const ret = $.let(none, OptionType(type));
|
|
237
|
-
$.match(state_read(key_expr), {
|
|
238
|
-
some: ($, v) => {
|
|
239
|
-
$.assign(ret, East.value(some(v.decodeBeast(type, "v2")), OptionType(type)));
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
return ret;
|
|
243
|
-
});
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* Creates a typed state initialization function that only writes if the key doesn't exist.
|
|
41
|
+
* @param key - The state key to check
|
|
42
|
+
* @returns Boolean indicating whether the key exists
|
|
247
43
|
*
|
|
248
44
|
* @remarks
|
|
249
|
-
*
|
|
250
|
-
* The write only occurs if the key is not already set, preventing overwrites
|
|
251
|
-
* on re-renders. Use this for setting up initial state in components.
|
|
252
|
-
*
|
|
253
|
-
* @typeParam T - The East type of the value to initialize
|
|
254
|
-
* @param key - The string key to initialize
|
|
255
|
-
* @param value - The default value to write (not wrapped in option)
|
|
256
|
-
* @param type - The East type descriptor for the value
|
|
257
|
-
* @returns A callable East function that performs the conditional initialization
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* ```ts
|
|
261
|
-
* import { East, IntegerType } from "@elaraai/east";
|
|
262
|
-
* import { State, UIComponentType, Button } from "@elaraai/east-ui";
|
|
263
|
-
*
|
|
264
|
-
* const counter = East.function([], UIComponentType, $ => {
|
|
265
|
-
* // Initialize to 0 only if not already set
|
|
266
|
-
* $(State.initTyped("counter", 0n, IntegerType)());
|
|
267
|
-
*
|
|
268
|
-
* // Read and display
|
|
269
|
-
* const count = $.let(State.readTyped("counter", IntegerType)());
|
|
270
|
-
* // ...
|
|
271
|
-
* });
|
|
272
|
-
* ```
|
|
45
|
+
* Implementation provided by `StateImpl` in `@elaraai/east-ui-components`.
|
|
273
46
|
*/
|
|
274
|
-
export const
|
|
275
|
-
return East.function([], NullType, $ => {
|
|
276
|
-
const key_expr = East.value(key);
|
|
277
|
-
const value_expr = East.value(value, type);
|
|
278
|
-
$.match(state_read(key_expr), {
|
|
279
|
-
none: ($) => {
|
|
280
|
-
$(state_write(key_expr, some(East.Blob.encodeBeast(value_expr, "v2"))));
|
|
281
|
-
},
|
|
282
|
-
});
|
|
283
|
-
return null;
|
|
284
|
-
});
|
|
285
|
-
};
|
|
47
|
+
export const state_has = East.platform("state_has", [StringType], BooleanType);
|
|
286
48
|
//# sourceMappingURL=state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/platform/state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/platform/state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAExE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAC1C,YAAY,EACZ,CAAC,GAAG,CAAC,EACL,CAAC,UAAU,CAAC,EACZ,GAAG,CACN,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAC3C,aAAa,EACb,CAAC,GAAG,CAAC,EACL,CAAC,UAAU,EAAE,GAAG,CAAC,EACjB,QAAQ,CACX,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
import { type ExprType, type
|
|
5
|
+
import { type ExprType, type CallableFunctionExpr } from "@elaraai/east";
|
|
6
6
|
import { UIComponentType } from "../component.js";
|
|
7
7
|
/**
|
|
8
8
|
* Creates a reactive component that re-renders independently when its dependencies change.
|
|
@@ -44,7 +44,7 @@ import { UIComponentType } from "../component.js";
|
|
|
44
44
|
* });
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
declare function createReactive(body:
|
|
47
|
+
declare function createReactive(body: CallableFunctionExpr<[], typeof UIComponentType>): ExprType<typeof UIComponentType>;
|
|
48
48
|
/**
|
|
49
49
|
* Reactive component for selective re-rendering.
|
|
50
50
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reactive/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reactive/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,KAAK,QAAQ,EAAW,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAExF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAMlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,iBAAS,cAAc,CACnB,IAAI,EAAE,oBAAoB,CAAC,EAAE,EAAE,OAAO,eAAe,CAAC,GACvD,QAAQ,CAAC,OAAO,eAAe,CAAC,CAMlC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ;IACjB;;;;;;;OAOG;;CAEG,CAAC"}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
import { East, variant
|
|
5
|
+
import { East, variant } from "@elaraai/east";
|
|
6
6
|
import { UIComponentType } from "../component.js";
|
|
7
|
-
import { OutOfScopeException } from "@elaraai/east/internal";
|
|
8
7
|
// ============================================================================
|
|
9
8
|
// Reactive Component Builder
|
|
10
9
|
// ============================================================================
|
|
@@ -49,25 +48,10 @@ import { OutOfScopeException } from "@elaraai/east/internal";
|
|
|
49
48
|
* ```
|
|
50
49
|
*/
|
|
51
50
|
function createReactive(body) {
|
|
52
|
-
// Create the inner render function
|
|
53
|
-
const renderFn = East.function([], UIComponentType, body);
|
|
54
51
|
// Get the IR and validate no captures from parent scope
|
|
55
|
-
try {
|
|
56
|
-
renderFn.toIR();
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
if (e instanceof OutOfScopeException) {
|
|
60
|
-
throw new Error(`Reactive.Root body must be a free function with no captures from parent scope. ` +
|
|
61
|
-
`Found capture from variable defined at ${printLocations(e.definedLocation)}. ` +
|
|
62
|
-
`Move state reads inside the Reactive body or use State for shared data.`);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw e;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
52
|
// Return the ReactiveComponent variant
|
|
69
53
|
return East.value(variant("ReactiveComponent", {
|
|
70
|
-
render:
|
|
54
|
+
render: body
|
|
71
55
|
}), UIComponentType);
|
|
72
56
|
}
|
|
73
57
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reactive/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reactive/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAiB,OAAO,EAA6B,MAAM,eAAe,CAAC;AAExF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,+EAA+E;AAC/E,6BAA6B;AAC7B,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,SAAS,cAAc,CACnB,IAAsD;IAEtD,wDAAwD;IACxD,uCAAuC;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE;QAC3C,MAAM,EAAE,IAAI;KACf,CAAC,EAAE,eAAe,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB;;;;;;;OAOG;IACH,IAAI,EAAE,cAAc;CACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elaraai/east-ui",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.23",
|
|
4
4
|
"description": "East UI - UI components for East language",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"node": ">=22.0.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
+
"@elaraai/east-node-std": "^0.0.1-beta.19",
|
|
75
76
|
"@fortawesome/fontawesome-common-types": "^7.1.0",
|
|
76
77
|
"@types/node": "^22.18.1",
|
|
77
78
|
"@typescript-eslint/eslint-plugin": "^8.42.0",
|