mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-03 11:37:09 +00:00
feat(spec): accept optional name on extract()
Add an (name, getter) overload so each extractor handle carries a
debuggable label that future trace fields (per-step diffs) can key
off. The web-runtime falls back to extractor_\${index} when none is
supplied so existing call sites keep working unchanged.
This commit is contained in:
1 parent
7291d5965b
commit
6fdbf9d2ab
3 files changed
+22
-5
No files matched your search
@@ -20,6 +20,7 @@ interface Handle {
|
||||
interface ExtractorEntry {
|
||||
getter: (state: unknown) => unknown;
|
||||
handle: Handle;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface ActionGeneratorHandle {
|
||||
@@ -290,9 +291,14 @@ function buildState(): unknown {
|
||||
}
|
||||
|
||||
const runtime = {
|
||||
extract<T>(getter: (state: unknown) => T): Handle {
|
||||
extract<T>(getter: (state: unknown) => T, name?: string): Handle {
|
||||
const handle: Handle = { current: undefined, previous: undefined };
|
||||
extractors.push({ getter: getter as (s: unknown) => unknown, handle });
|
||||
const resolvedName = name && name.length > 0 ? name : `extractor_${extractors.length}`;
|
||||
extractors.push({
|
||||
getter: getter as (s: unknown) => unknown,
|
||||
handle,
|
||||
name: resolvedName,
|
||||
});
|
||||
return handle;
|
||||
},
|
||||
always: noopFormula,
|
||||
|
||||
Reference in new issue
Block a user