diff --git a/src/core/commands/variableCommands.ts b/src/core/commands/variableCommands.ts index 7f935c38..9a58059a 100644 --- a/src/core/commands/variableCommands.ts +++ b/src/core/commands/variableCommands.ts @@ -25,7 +25,7 @@ import { requireBehavior, requireVariableOwner } from './require'; /** * The variable's default value is written to `props` as well. On a behavior a new variable starts - * out kept between calls (#229). + * at its default every call; "Keep" is switched on by hand (#229). */ export class AddVariableCommand implements Command { readonly label: string; @@ -47,14 +47,12 @@ export class AddVariableCommand implements Command { throw new CommandError(`Variable "${this.def.key}" already exists`); asset.variables.push(this.def); asset.props[this.def.key] = this.def.default; - if (asset.type === 'behavior') setKeptVariable(asset, this.def.key, true); } undo(project: Project): void { const asset = requireVariableOwner(project, this.assetId); asset.variables = asset.variables.filter((v) => v.key !== this.def.key); delete asset.props[this.def.key]; - if (asset.type === 'behavior') setKeptVariable(asset, this.def.key, false); } } diff --git a/src/core/model/Asset.ts b/src/core/model/Asset.ts index 5516ff9c..30e057c8 100644 --- a/src/core/model/Asset.ts +++ b/src/core/model/Asset.ts @@ -36,7 +36,7 @@ export interface SceneAsset extends AssetBase { * * `keptVariables` names the variables a `Run behavior` call hands on to the next call from the same * node on the same object (#229); the others start at their default every call. Absent keeps none, - * so a project from before the switch runs as it did – a variable added since starts out kept. + * so a project from before the switch runs as it did, and a new variable starts out not kept. */ export interface BehaviorAsset extends AssetBase { type: 'behavior'; diff --git a/tests/core/keep-state.test.ts b/tests/core/keep-state.test.ts index e1967b60..e2804b9e 100644 --- a/tests/core/keep-state.test.ts +++ b/tests/core/keep-state.test.ts @@ -36,11 +36,11 @@ import { /** * A behavior that counts its calls in `count` and hands the new count out as `out1`. `steps` - * counts the same way but is switched off, so it shows what an unkept variable does meanwhile. + * counts the same way but is left off, so it shows what an unkept variable does meanwhile. */ function counter(fixture: ProjectFixture): BehaviorAsset { const callee = makeBehavior(fixture, 'Counter', ['count', 'steps']); - fixture.stack.execute(new SetVariableKeptCommand(callee.id, 'steps', false)); + fixture.stack.execute(new SetVariableKeptCommand(callee.id, 'count', true)); const edit = graphEditor(fixture, callee); const start = edit.addNode(BEHAVIOR_START); const end = edit.addNode(BEHAVIOR_END); @@ -105,10 +105,10 @@ function threeCalls(fixture: ProjectFixture, callee: BehaviorAsset): unknown[][] } describe('Keep on a behavior variable (#229)', () => { - it('starts on for a variable added to a behavior, and off on a Variables asset', () => { + it('starts off for a variable added to a behavior, and on a Variables asset', () => { const fixture = makeProject(); const behavior = makeBehavior(fixture, 'B', ['count']); - expect(behavior.keptVariables).toEqual(['count']); + expect('keptVariables' in behavior).toBe(false); const shared = new CreateAssetCommand('variables', 'Shared'); fixture.stack.execute(shared); fixture.stack.execute(new AddVariableCommand(shared.asset.id, 'score', 'number')); diff --git a/tools/e2e/19-nested-behavior.mjs b/tools/e2e/19-nested-behavior.mjs index fd2fa946..4b30ba31 100644 --- a/tools/e2e/19-nested-behavior.mjs +++ b/tools/e2e/19-nested-behavior.mjs @@ -129,7 +129,7 @@ export async function nestedBehavior(t) { await shot('37-nested-behavior'); // 19c-ii. Keep (#229) is a switch on each variable of the called behavior, not on the node: a new - // variable starts kept, a click on its Keep button lets it go, and undo keeps it again. + // variable starts unkept, a click on its Keep button keeps it, and undo lets it go again. const kept = async () => JSON.stringify((await asset('nb-double')).keptVariables ?? []); const nodeKeys = Object.keys((await asset('nb-caller')).graph.nodes.find((n) => n.id === 'nb-call').params); await t.select({ kind: 'asset', assetId: 'nb-double' }); @@ -147,13 +147,13 @@ export async function nestedBehavior(t) { await undo(); await undo(); check( - 'a variable has a Keep switch: on when added, off by a click, on by the next, off after undo', + 'a variable has a Keep switch: off when added, on by a click, off by the next, on after undo', !nodeKeys.includes('keepState') && - keptAdded === '["var1"]' && + keptAdded === '[]' && Boolean(keepButton) && - keptClicked === '[]' && - keptReclicked === '["var1"]' && - keptUndone === '[]' && + keptClicked === '["var1"]' && + keptReclicked === '[]' && + keptUndone === '["var1"]' && (await kept()) === '[]', `node=${nodeKeys} added=${keptAdded} button=${JSON.stringify(keepButton)} clicked=${keptClicked} reclicked=${keptReclicked} undone=${keptUndone} after=${await kept()}`, );