MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / arkuiStateBuildEdges

Function arkuiStateBuildEdges

src/resolution/callback-synthesizer.ts:494–536  ·  view source on GitHub ↗

* Phase 4b-ets: ArkUI state → build (the ArkTS analog of react-render / * flutter-build). Assigning a reactive-decorated property (`@State count`, * `@Link selected`, …) re-runs the `@Component struct`'s `build()`, but that * hop is framework-internal — no static edge — so "onClick → markAllDone

(queries: QueryBuilder, ctx: ResolutionContext, onYield: MaybeYield)

Source from the content-addressed store, hash-verified

492 * all-sibling-methods design would erase).
493 */
494async function arkuiStateBuildEdges(queries: QueryBuilder, ctx: ResolutionContext, onYield: MaybeYield): Promise<Edge[]> {
495 let scanned255 = 0;
496 const edges: Edge[] = [];
497 const seen = new Set<string>();
498 for (const struct of queries.iterateNodesByKindIn('struct', ['arkts'])) {
499 if ((++scanned255 & 63) === 0) await onYield();
500 const children = queries.getOutgoingEdges(struct.id, ['contains'])
501 .map((e) => queries.getNodeById(e.target))
502 .filter((n): n is Node => !!n);
503 const build = children.find((n) => n.kind === 'method' && n.name === 'build');
504 if (!build) continue;
505 const reactiveProps = children.filter(
506 (n) => n.kind === 'property' && (n.decorators ?? []).some((d) => ARKUI_REACTIVE_DECORATORS.has(d))
507 );
508 if (reactiveProps.length === 0) continue;
509 const propAlternation = reactiveProps
510 .map((p) => p.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
511 .join('|');
512 // `this.count = …` / `+=` / `++` / `--` / `this.todos.push(…)`. The
513 // `=(?!=)` keeps `this.done == x` comparisons out.
514 const mutationRe = new RegExp(
515 `this\\.(?:${propAlternation})\\s*(?:=(?!=)|\\+\\+|--|[+\\-*/%&|^]=|\\.(?:${ARKUI_ARRAY_MUTATORS})\\s*\\()`
516 );
517 let added = 0;
518 for (const m of children) {
519 if (added >= MAX_CALLBACKS_PER_CHANNEL) break;
520 if (m.kind !== 'method' || m.id === build.id) continue;
521 const content = ctx.readFile(m.filePath);
522 const src = content && sliceLines(content, m.startLine, m.endLine);
523 if (!src || !mutationRe.test(stripCommentsForRegex(src, 'typescript'))) continue;
524 const key = `${m.id}>${build.id}`;
525 if (seen.has(key)) continue;
526 seen.add(key);
527 edges.push({
528 source: m.id, target: build.id, kind: 'calls', line: m.startLine,
529 provenance: 'heuristic',
530 metadata: { synthesizedBy: 'arkui-state', via: 'state assignment', registeredAt: `${build.filePath}:${build.startLine}` },
531 });
532 added++;
533 }
534 }
535 return edges;
536}
537
538/** Emit/subscribe call sites of HarmonyOS's `@ohos.events.emitter` bus. */
539const ARKUI_EMITTER_CALL_RE = /\bemitter\s*\.\s*(emit|on|once)\s*\(\s*([A-Za-z_$][\w$.]*|\{[^)]{0,120}?\beventId\s*:\s*[^,}]+[^)]*?\})/g;

Callers 1

Calls 11

stripCommentsForRegexFunction · 0.90
sliceLinesFunction · 0.85
iterateNodesByKindInMethod · 0.80
mapMethod · 0.80
hasMethod · 0.80
readFileMethod · 0.80
addMethod · 0.80
pushMethod · 0.80
getNodeByIdMethod · 0.65
getOutgoingEdgesMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected