@geastack/geatsc-plugin-gea 0.1.6
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/LICENSE +202 -0
- package/README.md +37 -0
- package/dist/analyze.d.ts +4 -0
- package/dist/analyze.js +195 -0
- package/dist/cpp-canvas-colors.d.ts +4 -0
- package/dist/cpp-canvas-colors.js +226 -0
- package/dist/cpp-field-access.d.ts +49 -0
- package/dist/cpp-field-access.js +144 -0
- package/dist/cpp-ir-dom-style.d.ts +1 -0
- package/dist/cpp-ir-dom-style.js +49 -0
- package/dist/cpp-ir.d.ts +30 -0
- package/dist/cpp-ir.js +2426 -0
- package/dist/cpp-keyed-component-diagnostics.d.ts +8 -0
- package/dist/cpp-keyed-component-diagnostics.js +74 -0
- package/dist/cpp-keyed-list-diagnostics.d.ts +17 -0
- package/dist/cpp-keyed-list-diagnostics.js +84 -0
- package/dist/cpp-mounted-lowering.d.ts +81 -0
- package/dist/cpp-mounted-lowering.js +2235 -0
- package/dist/cpp-mounted.d.ts +25 -0
- package/dist/cpp-mounted.js +1376 -0
- package/dist/cpp-reactive-component-diagnostics.d.ts +2 -0
- package/dist/cpp-reactive-component-diagnostics.js +76 -0
- package/dist/cpp-reactive-component.d.ts +14 -0
- package/dist/cpp-reactive-component.js +349 -0
- package/dist/cpp-replacements.d.ts +14 -0
- package/dist/cpp-replacements.js +787 -0
- package/dist/cpp-source-replacements.d.ts +11 -0
- package/dist/cpp-source-replacements.js +257 -0
- package/dist/cpp-store-hub.d.ts +7 -0
- package/dist/cpp-store-hub.js +160 -0
- package/dist/cpp-store-method-body-parser.d.ts +2 -0
- package/dist/cpp-store-method-body-parser.js +392 -0
- package/dist/cpp-store-method-context.d.ts +48 -0
- package/dist/cpp-store-method-context.js +114 -0
- package/dist/cpp-store-method-expressions.d.ts +12 -0
- package/dist/cpp-store-method-expressions.js +1263 -0
- package/dist/cpp-store-method-replacements.d.ts +5 -0
- package/dist/cpp-store-method-replacements.js +1521 -0
- package/dist/cpp-store-method-targets.d.ts +19 -0
- package/dist/cpp-store-method-targets.js +296 -0
- package/dist/cpp-store-typed-arrays.d.ts +2 -0
- package/dist/cpp-store-typed-arrays.js +655 -0
- package/dist/cpp-stores.d.ts +73 -0
- package/dist/cpp-stores.js +1739 -0
- package/dist/cpp-template-renderer.d.ts +23 -0
- package/dist/cpp-template-renderer.js +3530 -0
- package/dist/css-style-declaration-shims.d.ts +3 -0
- package/dist/css-style-declaration-shims.js +47 -0
- package/dist/host-declarations.d.ts +11 -0
- package/dist/host-declarations.js +320 -0
- package/dist/host-shims.d.ts +3 -0
- package/dist/host-shims.js +3217 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1239 -0
- package/dist/load-ir.d.ts +7 -0
- package/dist/load-ir.js +40 -0
- package/dist/types.d.ts +604 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.js +723 -0
- package/dist/validate.d.ts +3 -0
- package/dist/validate.js +226 -0
- package/package.json +57 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RendererReplacement {
|
|
2
|
+
className: string;
|
|
3
|
+
rendererName: string;
|
|
4
|
+
mountedRendererName?: string;
|
|
5
|
+
stateReaderName?: string;
|
|
6
|
+
storeExpression?: string;
|
|
7
|
+
refFields?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function replaceGeneratedRenderers(source: string, replacements: RendererReplacement[]): string;
|
|
10
|
+
export declare function replaceOutOfLineGeneratedRenderers(source: string, replacements: RendererReplacement[]): string;
|
|
11
|
+
export declare function bridgeGeneratedComponentRenderers(source: string, replacements: RendererReplacement[], mountedRendererDeclarations: string, typedStoreAccessorTypes?: ReadonlyMap<string, string>): string;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { sanitizeCppIdentifier } from './utils.js';
|
|
2
|
+
export function replaceGeneratedRenderers(source, replacements) {
|
|
3
|
+
let next = source;
|
|
4
|
+
for (const replacement of replacements)
|
|
5
|
+
next = replaceGeneratedRenderer(next, replacement);
|
|
6
|
+
return next;
|
|
7
|
+
}
|
|
8
|
+
// The multi-file (module-first) split puts a component class's DECLARATION in
|
|
9
|
+
// the module header and its method BODIES out-of-line in the module .cpp
|
|
10
|
+
// (`NodeHandle App::<template>(const auto &d) const { … }`). The in-class
|
|
11
|
+
// replacement above only ever sees the header, so on that split the boxed
|
|
12
|
+
// template body survived untouched next to the native mounted renderer that
|
|
13
|
+
// supersedes it — for bubble-grid that meant `__gea_with_boxed_dispatch_arity`
|
|
14
|
+
// lambdas, boxed property reads, and a second registration of every touch
|
|
15
|
+
// handler through `fn_delegateEvent(..., std::vector<std::vector<gea_cpp_value>>)`.
|
|
16
|
+
// Rewrite those out-of-line bodies to the same native mount the header form uses.
|
|
17
|
+
export function replaceOutOfLineGeneratedRenderers(source, replacements) {
|
|
18
|
+
let next = source;
|
|
19
|
+
for (const replacement of replacements)
|
|
20
|
+
next = replaceOutOfLineGeneratedRenderer(next, replacement);
|
|
21
|
+
return next;
|
|
22
|
+
}
|
|
23
|
+
// geatsc encodes a module-scoped member name (`__sym_GEA_CREATE_TEMPLATE` ->
|
|
24
|
+
// `gea_m_e_u005f_u005fsym_u005fGEA_u005fCREATE_u005fTEMPLATE`), so match the
|
|
25
|
+
// shape rather than either literal spelling.
|
|
26
|
+
const OUT_OF_LINE_TEMPLATE_METHOD = '[A-Za-z0-9_]*sym[A-Za-z0-9_]*GEA[A-Za-z0-9_]*(?:CREATE|STATIC)[A-Za-z0-9_]*TEMPLATE';
|
|
27
|
+
function replaceOutOfLineGeneratedRenderer(source, replacement) {
|
|
28
|
+
if (!replacement.mountedRendererName || !replacement.storeExpression)
|
|
29
|
+
return source;
|
|
30
|
+
const definition = new RegExp(`(^|\\n)\\s*([A-Za-z_][\\w:]*(?:\\s*<[^>\\n]*>)?)\\s+${replacement.className}::${OUT_OF_LINE_TEMPLATE_METHOD}\\s*\\([^;{}\\n]*\\)\\s*(?:const\\s*)?\\{`);
|
|
31
|
+
const match = definition.exec(source);
|
|
32
|
+
if (!match)
|
|
33
|
+
return source;
|
|
34
|
+
const returnType = match[2];
|
|
35
|
+
const bodyOpen = source.indexOf('{', match.index + match[0].length - 1);
|
|
36
|
+
if (bodyOpen < 0)
|
|
37
|
+
return source;
|
|
38
|
+
const bodyClose = findMatchingBrace(source, bodyOpen);
|
|
39
|
+
if (bodyClose < 0)
|
|
40
|
+
return source;
|
|
41
|
+
const body = rendererBody(replacement, returnType, source);
|
|
42
|
+
return `${source.slice(0, bodyOpen)}${body}${source.slice(bodyClose + 1)}`;
|
|
43
|
+
}
|
|
44
|
+
// A module-first app can contain a compatibility-rendered parent whose child
|
|
45
|
+
// already has a native mounted renderer. The parent still constructs the child
|
|
46
|
+
// class and calls render()/dispose(), so replacing the child module with an
|
|
47
|
+
// empty native stub leaves an incomplete class. Keep the lightweight generated
|
|
48
|
+
// class in that boundary module, replace its large static template with the
|
|
49
|
+
// native mount, and add the two lifecycle methods the compatibility parent
|
|
50
|
+
// expects.
|
|
51
|
+
export function bridgeGeneratedComponentRenderers(source, replacements, mountedRendererDeclarations, typedStoreAccessorTypes = new Map()) {
|
|
52
|
+
let next = replaceGeneratedRenderers(source, replacements);
|
|
53
|
+
const analysisSource = `${next}\n${mountedRendererDeclarations}`;
|
|
54
|
+
for (const replacement of replacements) {
|
|
55
|
+
if (!replacement.mountedRendererName || !replacement.storeExpression)
|
|
56
|
+
continue;
|
|
57
|
+
next = insertComponentBridgeMethods(next, replacement, analysisSource, typedStoreAccessorTypes);
|
|
58
|
+
}
|
|
59
|
+
return next;
|
|
60
|
+
}
|
|
61
|
+
function insertComponentBridgeMethods(source, replacement, analysisSource, typedStoreAccessorTypes) {
|
|
62
|
+
const classOpen = findClassOpenBrace(source, replacement.className);
|
|
63
|
+
if (classOpen < 0)
|
|
64
|
+
return source;
|
|
65
|
+
const classClose = findMatchingBrace(source, classOpen);
|
|
66
|
+
if (classClose < 0)
|
|
67
|
+
return source;
|
|
68
|
+
const classBody = source.slice(classOpen, classClose);
|
|
69
|
+
if (classBody.includes('__gea_native_mount_disposer'))
|
|
70
|
+
return source;
|
|
71
|
+
const mountCall = `gea_ir::${replacement.mountedRendererName}(${mountStoreArgument(replacement, analysisSource, typedStoreAccessorTypes)}, __gea_native_mount_disposer)`;
|
|
72
|
+
const methods = [
|
|
73
|
+
'',
|
|
74
|
+
' mutable std::shared_ptr<gea_ir::NativeDisposer> __gea_native_mount_disposer;',
|
|
75
|
+
' mutable gea_cpp_value el = gea_cpp_value::missing();',
|
|
76
|
+
'',
|
|
77
|
+
' void render(gea_cpp_value parent = gea_cpp_value::missing(), gea_cpp_value _index = gea_cpp_value::missing()) const {',
|
|
78
|
+
' (void)_index;',
|
|
79
|
+
' if (__gea_native_mount_disposer) __gea_native_mount_disposer->dispose();',
|
|
80
|
+
' __gea_native_mount_disposer = std::make_shared<gea_ir::NativeDisposer>();',
|
|
81
|
+
` auto node = ${mountCall};`,
|
|
82
|
+
' const int parent_id = gea_ir::nodeIdFromValue(parent);',
|
|
83
|
+
' if (parent_id >= 0) gea::embedded::ui::NodeHandle(parent_id).appendChild(node);',
|
|
84
|
+
' el = gea_ir::nodeValue(node);',
|
|
85
|
+
' }',
|
|
86
|
+
'',
|
|
87
|
+
' void dispose() {',
|
|
88
|
+
' if (__gea_native_mount_disposer) __gea_native_mount_disposer->dispose();',
|
|
89
|
+
' __gea_native_mount_disposer.reset();',
|
|
90
|
+
' el = gea_cpp_value::missing();',
|
|
91
|
+
' }',
|
|
92
|
+
'',
|
|
93
|
+
].join('\n');
|
|
94
|
+
return `${source.slice(0, classClose)}${methods}${source.slice(classClose)}`;
|
|
95
|
+
}
|
|
96
|
+
function replaceGeneratedRenderer(source, replacement) {
|
|
97
|
+
const classOpen = findClassOpenBrace(source, replacement.className);
|
|
98
|
+
if (classOpen < 0)
|
|
99
|
+
return source;
|
|
100
|
+
const classClose = findMatchingBrace(source, classOpen);
|
|
101
|
+
if (classClose < 0)
|
|
102
|
+
return source;
|
|
103
|
+
const methodName = '__sym_GEA_STATIC_TEMPLATE';
|
|
104
|
+
const methodNameStart = source.indexOf(methodName, classOpen);
|
|
105
|
+
if (methodNameStart < 0 || methodNameStart > classClose)
|
|
106
|
+
return source;
|
|
107
|
+
const methodOpen = source.indexOf('{', methodNameStart);
|
|
108
|
+
if (methodOpen < 0 || methodOpen > classClose)
|
|
109
|
+
return source;
|
|
110
|
+
const methodClose = findMatchingBrace(source, methodOpen);
|
|
111
|
+
if (methodClose < 0 || methodClose > classClose)
|
|
112
|
+
return source;
|
|
113
|
+
const body = rendererBody(replacement, staticTemplateReturnType(source), source);
|
|
114
|
+
return `${source.slice(0, methodOpen)}${body}${source.slice(methodClose + 1)}`;
|
|
115
|
+
}
|
|
116
|
+
function findClassOpenBrace(source, className) {
|
|
117
|
+
const pattern = new RegExp(`\\bclass\\s+${escapeRegExp(className)}\\b`, 'g');
|
|
118
|
+
let match;
|
|
119
|
+
while ((match = pattern.exec(source)) !== null) {
|
|
120
|
+
const brace = source.indexOf('{', match.index);
|
|
121
|
+
if (brace < 0)
|
|
122
|
+
return -1;
|
|
123
|
+
const semicolon = source.indexOf(';', match.index);
|
|
124
|
+
if (semicolon < 0 || brace < semicolon)
|
|
125
|
+
return brace;
|
|
126
|
+
}
|
|
127
|
+
return -1;
|
|
128
|
+
}
|
|
129
|
+
// Detect the return type geatsc gave `CompiledStaticComponent::__sym_GEA_STATIC_TEMPLATE`.
|
|
130
|
+
// When TS `Node` resolves to a concrete type it lowers to `gea::embedded::ui::NodeHandle`
|
|
131
|
+
// (the IR `mount_*` renderers already return exactly that), letting templates flow as a
|
|
132
|
+
// typed handle with no record bridge. When `Node` is unresolved it falls back to the
|
|
133
|
+
// type-erased `gea_cpp_value`. The component overrides must match whichever the base used,
|
|
134
|
+
// so derive it from the base class rather than hard-coding either form.
|
|
135
|
+
function staticTemplateReturnType(source) {
|
|
136
|
+
const open = findClassOpenBrace(source, 'CompiledStaticComponent');
|
|
137
|
+
if (open < 0)
|
|
138
|
+
return 'gea_cpp_value';
|
|
139
|
+
const close = findMatchingBrace(source, open);
|
|
140
|
+
if (close < 0)
|
|
141
|
+
return 'gea_cpp_value';
|
|
142
|
+
const methodStart = source.indexOf('__sym_GEA_STATIC_TEMPLATE', open);
|
|
143
|
+
if (methodStart < 0 || methodStart > close)
|
|
144
|
+
return 'gea_cpp_value';
|
|
145
|
+
const lineStart = source.lastIndexOf('\n', methodStart) + 1;
|
|
146
|
+
const declaration = source.slice(lineStart, methodStart);
|
|
147
|
+
const match = declaration.match(/(?:virtual\s+)?([A-Za-z_][\w:]*(?:\s*<[^>]*>)?)\s*$/);
|
|
148
|
+
return match ? match[1] : 'gea_cpp_value';
|
|
149
|
+
}
|
|
150
|
+
function returnsNodeHandle(returnType) {
|
|
151
|
+
return returnType.includes('NodeHandle');
|
|
152
|
+
}
|
|
153
|
+
// The mount renderer's typed store-param class, parsed from the mount
|
|
154
|
+
// declaration already inserted into the source (the early gea_ir block is in
|
|
155
|
+
// by shell-insertion time) — the single source of truth for the param flavor.
|
|
156
|
+
// Null = boxed gea_cpp_value param.
|
|
157
|
+
function mountStoreParamClass(source, mountedRendererName) {
|
|
158
|
+
const match = source.match(new RegExp(`NodeHandle ${escapeRegExp(mountedRendererName)}\\(const std::shared_ptr<([A-Za-z_][\\w:]*)> &store`));
|
|
159
|
+
return match ? match[1] : null;
|
|
160
|
+
}
|
|
161
|
+
// The return type of the geatsc-core global accessor for `globalName`, read
|
|
162
|
+
// from the program's forward declarations or definitions. Some typed store
|
|
163
|
+
// globals are first seen as function bodies (`std::shared_ptr<T>& f() { ... }`)
|
|
164
|
+
// before this replacement pass inserts its shell declarations.
|
|
165
|
+
// 'gea_cpp_value' when absent.
|
|
166
|
+
function globalAccessorReturnType(source, globalName, typedStoreAccessorTypes = new Map()) {
|
|
167
|
+
const typedStoreAccessorType = typedStoreAccessorTypes.get(globalName);
|
|
168
|
+
if (typedStoreAccessorType)
|
|
169
|
+
return typedStoreAccessorType;
|
|
170
|
+
const match = source.match(new RegExp(`(?:^|\\n)([^\\n;{}()]+?) &__gea_global_${escapeRegExp(globalName)}\\(\\)\\s*(?:;|\\{)`));
|
|
171
|
+
return match ? match[1].trim() : 'gea_cpp_value';
|
|
172
|
+
}
|
|
173
|
+
// The argument the shell passes into `mount_<Name>`: the global accessor as
|
|
174
|
+
// is when its flavor matches the mount param; boxed through gea_cpp_key when
|
|
175
|
+
// a TYPED global cell feeds a boxed mount param (the retained tracked proxy,
|
|
176
|
+
// not a snapshot).
|
|
177
|
+
function mountStoreArgument(replacement, source, typedStoreAccessorTypes = new Map()) {
|
|
178
|
+
const expression = replacement.storeExpression;
|
|
179
|
+
const expr = rendererStoreExpression(expression);
|
|
180
|
+
if (!replacement.mountedRendererName)
|
|
181
|
+
return expr;
|
|
182
|
+
if (mountStoreParamClass(source, replacement.mountedRendererName))
|
|
183
|
+
return expr;
|
|
184
|
+
if (isIdentifier(expression) && globalAccessorReturnType(source, sanitizeCppIdentifier(expression), typedStoreAccessorTypes).startsWith('std::shared_ptr<')) {
|
|
185
|
+
return `gea_cpp_key(${expr})`;
|
|
186
|
+
}
|
|
187
|
+
return expr;
|
|
188
|
+
}
|
|
189
|
+
// Emit the body that produces the static template's `Node`. The IR `mount_*` renderers
|
|
190
|
+
// return a `gea::embedded::ui::NodeHandle`; when the method is typed on it we return that
|
|
191
|
+
// straight through (no bridge). When the base fell back to `gea_cpp_value` we wrap it in
|
|
192
|
+
// the `nodeValue` record so the override's return type still matches the base.
|
|
193
|
+
function rendererBody(replacement, returnType, source, typedStoreAccessorTypes = new Map()) {
|
|
194
|
+
const wrap = (expression) => returnsNodeHandle(returnType) ? expression : `gea_ir::nodeValue(${expression})`;
|
|
195
|
+
if (replacement.mountedRendererName && replacement.storeExpression) {
|
|
196
|
+
return [
|
|
197
|
+
'{',
|
|
198
|
+
' auto __gea_static_disposer = std::make_shared<gea_ir::NativeDisposer>();',
|
|
199
|
+
` return ${wrap(`gea_ir::${replacement.mountedRendererName}(${mountStoreArgument(replacement, source, typedStoreAccessorTypes)}, __gea_static_disposer)`)};`,
|
|
200
|
+
' }',
|
|
201
|
+
].join('\n');
|
|
202
|
+
}
|
|
203
|
+
if (!replacement.stateReaderName || !replacement.storeExpression) {
|
|
204
|
+
return ['{', ` return ${wrap(`gea_ir::${replacement.rendererName}()`)};`, ' }'].join('\n');
|
|
205
|
+
}
|
|
206
|
+
// Legacy state-reader path: only the boxed `read_<Store>_state(gea_cpp_value)`
|
|
207
|
+
// overload is declared this early, so a typed global cell boxes through
|
|
208
|
+
// gea_cpp_key (identity for boxed cells).
|
|
209
|
+
const stateStoreExpr = isIdentifier(replacement.storeExpression) &&
|
|
210
|
+
globalAccessorReturnType(source, sanitizeCppIdentifier(replacement.storeExpression), typedStoreAccessorTypes).startsWith('std::shared_ptr<')
|
|
211
|
+
? `gea_cpp_key(${rendererStoreExpression(replacement.storeExpression)})`
|
|
212
|
+
: rendererStoreExpression(replacement.storeExpression);
|
|
213
|
+
return [
|
|
214
|
+
'{',
|
|
215
|
+
` const auto __gea_ir_state = gea_ir::${replacement.stateReaderName}(${stateStoreExpr});`,
|
|
216
|
+
` return ${wrap(`gea_ir::${replacement.rendererName}(__gea_ir_state)`)};`,
|
|
217
|
+
' }',
|
|
218
|
+
].join('\n');
|
|
219
|
+
}
|
|
220
|
+
function rendererStoreExpression(expression) {
|
|
221
|
+
return isIdentifier(expression) ? `__gea_global_${sanitizeCppIdentifier(expression)}()` : expression;
|
|
222
|
+
}
|
|
223
|
+
function isIdentifier(expression) {
|
|
224
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(expression);
|
|
225
|
+
}
|
|
226
|
+
function findMatchingBrace(source, open) {
|
|
227
|
+
let depth = 0;
|
|
228
|
+
let quote = null;
|
|
229
|
+
let escaped = false;
|
|
230
|
+
for (let index = open; index < source.length; index += 1) {
|
|
231
|
+
const char = source[index];
|
|
232
|
+
if (quote) {
|
|
233
|
+
if (escaped)
|
|
234
|
+
escaped = false;
|
|
235
|
+
else if (char === '\\')
|
|
236
|
+
escaped = true;
|
|
237
|
+
else if (char === quote)
|
|
238
|
+
quote = null;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (char === '"' || char === "'") {
|
|
242
|
+
quote = char;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (char === '{')
|
|
246
|
+
depth += 1;
|
|
247
|
+
else if (char === '}') {
|
|
248
|
+
depth -= 1;
|
|
249
|
+
if (depth === 0)
|
|
250
|
+
return index;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return -1;
|
|
254
|
+
}
|
|
255
|
+
function escapeRegExp(text) {
|
|
256
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
257
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GeaIrBundleV1 } from './types.js';
|
|
2
|
+
export declare function storeHubEmissionEnabled(): boolean;
|
|
3
|
+
export declare function configureStoreDynamicFallback(enabled: boolean): void;
|
|
4
|
+
export declare function storeDynamicFallbackEnabled(): boolean;
|
|
5
|
+
export declare function decideStoreHubEmission(source: string, ir: GeaIrBundleV1 | null): boolean;
|
|
6
|
+
export declare function injectStoreSignalHub(source: string, ir: GeaIrBundleV1): string;
|
|
7
|
+
export declare function storeHubBindHelperLines(ir: GeaIrBundleV1): string[];
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Typed notification channel for regular Store-based AOT stores.
|
|
2
|
+
//
|
|
3
|
+
// Renderer bindings subscribe directly to a native SignalHub on the typed Store
|
|
4
|
+
// base. Store method replacement and normal typed field assignment notify that
|
|
5
|
+
// hub without routing through the old CompiledStore Proxy side tables.
|
|
6
|
+
// The typed Store base in hub mode gets the SignalHub plus a native `observe`
|
|
7
|
+
// method. The AOT keyed-list runtime calls `store.observe(prop, handler)` to
|
|
8
|
+
// re-reconcile a list field on change; in hub mode there is no dynamic observer
|
|
9
|
+
// channel, so route it through the hub. The handler is invoked with no payload
|
|
10
|
+
// (missing, missing) — the keyed-list handler re-resolves the current array from
|
|
11
|
+
// the typed field, so the value need not travel through the notification. Kept
|
|
12
|
+
// fully typed (no gea_cpp_value receiver) so the `store->observe(...)` call site
|
|
13
|
+
// binds to a real member instead of a boxed record dispatch.
|
|
14
|
+
// `observe` is a typed `std::function` member (NOT a method) so the keyed-list's
|
|
15
|
+
// `typeof store.observe === 'function'` probe — which reads `store->observe` as a
|
|
16
|
+
// value (a method can't be named as a value, a member can) — sees it and the
|
|
17
|
+
// subscription actually wires up at runtime. The stored type is a plain typed
|
|
18
|
+
// std::function (no gea_cpp_value receiver / no boxed storage); only the dynamic
|
|
19
|
+
// `typeof` query transiently views it as a callable value.
|
|
20
|
+
const HUB_SIGNAL = 'public:\n' +
|
|
21
|
+
' mutable gea::embedded::ui::SignalHub __gea_hub;\n';
|
|
22
|
+
const HUB_OBSERVE_FIELD = ' std::function<std::function<void()>(std::string, std::function<void(gea_cpp_value, gea_cpp_value)>)> observe =\n' +
|
|
23
|
+
' [this](std::string __gea_prop, std::function<void(gea_cpp_value, gea_cpp_value)> __gea_handler) -> std::function<void()> {\n' +
|
|
24
|
+
' std::size_t __gea_sub = __gea_hub.subscribe(__gea_prop.c_str(), [__gea_handler]() mutable { __gea_handler(gea_cpp_value::missing(), gea_cpp_value::missing()); });\n' +
|
|
25
|
+
' return [this, __gea_sub]() { __gea_hub.unsubscribe(__gea_sub); };\n' +
|
|
26
|
+
' };\n';
|
|
27
|
+
const HUB_MEMBER = HUB_SIGNAL + HUB_OBSERVE_FIELD;
|
|
28
|
+
let hubEmissionEnabled = false;
|
|
29
|
+
let storeDynamicFallback = false;
|
|
30
|
+
export function storeHubEmissionEnabled() {
|
|
31
|
+
return hubEmissionEnabled;
|
|
32
|
+
}
|
|
33
|
+
export function configureStoreDynamicFallback(enabled) {
|
|
34
|
+
void enabled;
|
|
35
|
+
storeDynamicFallback = false;
|
|
36
|
+
}
|
|
37
|
+
export function storeDynamicFallbackEnabled() {
|
|
38
|
+
return storeDynamicFallback;
|
|
39
|
+
}
|
|
40
|
+
export function decideStoreHubEmission(source, ir) {
|
|
41
|
+
hubEmissionEnabled = false;
|
|
42
|
+
if (!ir)
|
|
43
|
+
return false;
|
|
44
|
+
// Both compiled and lean IR stores are native typed store classes. Lean
|
|
45
|
+
// changes the generated method surface, not the notification transport:
|
|
46
|
+
// native field writes and mounted bindings still meet at the inherited hub.
|
|
47
|
+
if (!ir.stores.some((store) => !store.selfStore))
|
|
48
|
+
return false;
|
|
49
|
+
const hasBase = ['Store', 'CompiledStore', 'CompiledLeanStore'].some((base) => findClassBodyOpen(source, base) >= 0);
|
|
50
|
+
if (!hasBase)
|
|
51
|
+
return false;
|
|
52
|
+
hubEmissionEnabled = true;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
export function injectStoreSignalHub(source, ir) {
|
|
56
|
+
void ir;
|
|
57
|
+
if (!hubEmissionEnabled)
|
|
58
|
+
return source;
|
|
59
|
+
let next = source;
|
|
60
|
+
for (const base of ['Store', 'CompiledStore', 'CompiledLeanStore']) {
|
|
61
|
+
const open = findClassBodyOpen(next, base);
|
|
62
|
+
if (open < 0)
|
|
63
|
+
continue;
|
|
64
|
+
// The reactive runtime's CompiledLeanStore hand-writes its own `observe`
|
|
65
|
+
// method (routing through leanObserve); injecting the hub's `observe` field
|
|
66
|
+
// on top of it is a redeclaration. Emit only the SignalHub for such a class
|
|
67
|
+
// — field writes and renderer binds still route through `__gea_hub`, and the
|
|
68
|
+
// class's own `observe` is the observe API.
|
|
69
|
+
const body = classBodySlice(next, open);
|
|
70
|
+
const member = classBodyDeclaresObserveMember(body) ? HUB_SIGNAL : HUB_MEMBER;
|
|
71
|
+
next = `${next.slice(0, open + 1)}\n${member}${next.slice(open + 1)}`;
|
|
72
|
+
}
|
|
73
|
+
return next;
|
|
74
|
+
}
|
|
75
|
+
// A member declaration named `observe` (method `observe(` or field `observe =`),
|
|
76
|
+
// as opposed to a member-access call `x.observe(` / `store->observe(`.
|
|
77
|
+
function classBodyDeclaresObserveMember(classBody) {
|
|
78
|
+
return /(?<![\w.>:])observe\s*[(=]/.test(classBody);
|
|
79
|
+
}
|
|
80
|
+
// The `{ ... }` span of a class body starting at the opening brace, skipping
|
|
81
|
+
// string/char literals and comments so braces inside them do not unbalance the
|
|
82
|
+
// match. Used to scope the `observe` member scan to a single class.
|
|
83
|
+
function classBodySlice(source, openBraceIndex) {
|
|
84
|
+
let depth = 0;
|
|
85
|
+
for (let i = openBraceIndex; i < source.length; i++) {
|
|
86
|
+
const ch = source[i];
|
|
87
|
+
const nextCh = source[i + 1];
|
|
88
|
+
if (ch === '/' && nextCh === '/') {
|
|
89
|
+
const nl = source.indexOf('\n', i);
|
|
90
|
+
if (nl < 0)
|
|
91
|
+
return source.slice(openBraceIndex);
|
|
92
|
+
i = nl;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (ch === '/' && nextCh === '*') {
|
|
96
|
+
const end = source.indexOf('*/', i + 2);
|
|
97
|
+
if (end < 0)
|
|
98
|
+
return source.slice(openBraceIndex);
|
|
99
|
+
i = end + 1;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (ch === '"' || ch === "'") {
|
|
103
|
+
i++;
|
|
104
|
+
while (i < source.length) {
|
|
105
|
+
if (source[i] === '\\') {
|
|
106
|
+
i += 2;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (source[i] === ch)
|
|
110
|
+
break;
|
|
111
|
+
i++;
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (ch === '{')
|
|
116
|
+
depth++;
|
|
117
|
+
else if (ch === '}') {
|
|
118
|
+
depth--;
|
|
119
|
+
if (depth === 0)
|
|
120
|
+
return source.slice(openBraceIndex, i + 1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return source.slice(openBraceIndex);
|
|
124
|
+
}
|
|
125
|
+
// The typed bind helper, emitted once into the late gea_ir block. Run-once
|
|
126
|
+
// apply + microtask scheduling with per-binding dedup and disposer-registered
|
|
127
|
+
// teardown, registering through the typed hub (store->__gea_hub) rather than a
|
|
128
|
+
// dynamic observe channel.
|
|
129
|
+
export function storeHubBindHelperLines(ir) {
|
|
130
|
+
if (!hubEmissionEnabled)
|
|
131
|
+
return [];
|
|
132
|
+
if (!ir.stores.some((store) => !store.selfStore))
|
|
133
|
+
return [];
|
|
134
|
+
return [
|
|
135
|
+
'template <typename Store>',
|
|
136
|
+
'inline void gea_rc_bind_hub_apply(const std::shared_ptr<Store> &store, const std::shared_ptr<NativeDisposer> &disposer, std::initializer_list<const char *> deps, std::function<void()> apply) {',
|
|
137
|
+
' auto apply_fn = std::make_shared<std::function<void()>>(std::move(apply));',
|
|
138
|
+
' auto pending = std::make_shared<bool>(false);',
|
|
139
|
+
' gea_cpp_run_reactive_apply(apply_fn);',
|
|
140
|
+
' for (const char *dep : deps) {',
|
|
141
|
+
' auto __gea_sub_id = store->__gea_hub.subscribe(dep, [apply_fn, pending]() { gea_cpp_schedule_reactive_apply(apply_fn, pending); });',
|
|
142
|
+
' if (disposer) disposer->add([store, __gea_sub_id]() { store->__gea_hub.unsubscribe(__gea_sub_id); });',
|
|
143
|
+
' }',
|
|
144
|
+
' // Unsubscribing only stops FUTURE notifications — an apply already queued on',
|
|
145
|
+
' // the microtask queue still runs after disposal, against node ids the unmount',
|
|
146
|
+
' // freed (and the next mount may already have reused: stale keyed-list rebuilds',
|
|
147
|
+
' // then remove freshly-mounted nodes). Null the shared fn on dispose so the',
|
|
148
|
+
' // queued run is a no-op (gea_cpp_run_reactive_apply skips empty functions).',
|
|
149
|
+
' if (disposer) disposer->add([apply_fn]() { *apply_fn = nullptr; });',
|
|
150
|
+
'}',
|
|
151
|
+
'',
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
function findClassBodyOpen(source, className) {
|
|
155
|
+
const pattern = new RegExp(`\\bclass\\s+${className}\\b[^;{]*\\{`, 'g');
|
|
156
|
+
const match = pattern.exec(source);
|
|
157
|
+
if (!match)
|
|
158
|
+
return -1;
|
|
159
|
+
return match.index + match[0].length - 1;
|
|
160
|
+
}
|