* Apply an update to one function. `bumpVersion` is true for signature changes * (name/arguments/outputs declaration) so call sites detect staleness, and false for * pure output-expression edits. Version-bumping changes re-sync the body's fnargs.
(id: string, updater: (fn: FunctionDeclaration) => FunctionDeclaration, bumpVersion: boolean)
| 41 | * pure output-expression edits. Version-bumping changes re-sync the body's fnargs. |
| 42 | */ |
| 43 | function mutate(id: string, updater: (fn: FunctionDeclaration) => FunctionDeclaration, bumpVersion: boolean): void { |
| 44 | let next: FunctionDeclaration | undefined; |
| 45 | useEditorStore.getState().setFunctions((fns) => { |
| 46 | const fn = fns[id]; |
| 47 | if (!fn) return fns; |
| 48 | const updated = updater(fn); |
| 49 | next = bumpVersion ? { ...updated, version: fn.version + 1 } : updated; |
| 50 | return { ...fns, [id]: next }; |
| 51 | }); |
| 52 | if (next && bumpVersion) syncBody(next); |
| 53 | } |
| 54 | |
| 55 | /** Create a new (empty) function + its body canvas. Returns the new definition. */ |
| 56 | export function addFunction(): FunctionDeclaration { |
no test coverage detected