bindExternals function
void
bindExternals(
- SceneDocument doc,
- List<
ExternalWidget> declarations, { - List<
Token< tokens = const [],Object?> >
Gives every external node in doc the builder its label names.
A scene the app COMPILED needs none of this: each node holds its own generated arguments, which reach the declaration themselves. This is for a document that arrived as DATA — over the editor's wire, or read back from a saved pair — where the generated type could not travel and the label is all that did.
tokens are the app's declared tokens, for the opaque ones: an argument
that arrived as {'token': 'cta'} — the editor never held the object —
becomes the declared object here, before the builder sees it. A read
document is the only one that needs this; a compiled scene reads
tokens.cta itself.
Implementation
void bindExternals(
SceneDocument doc,
List<ExternalWidget> declarations, {
List<Token<Object?>> tokens = const [],
}) {
var byEntry = {for (var w in declarations) w.entry: w};
var byName = {for (var t in tokens) t.name: t.value};
for (var (node, _) in doc.walk()) {
resolveExports(node, byName);
if (node is! ExternalNode) continue;
var build = byEntry[node.entry]?.build;
node.builder = build == null
? null
: (args) => build(resolveTokenArgs(args, byName));
}
}