Browse Source

Name the variables in SequencePanel's save and remove

Rename s, n, b and l to slot, newName, newBpm and newBars (R3), and say
why the slot is copied before the await. The compiled component differs
only in these names and comments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude 2 hours ago
parent
commit
b3da0ea7d3
1 changed files with 12 additions and 11 deletions
  1. 12 11
      frontend/src/lib/SequencePanel.svelte

+ 12 - 11
frontend/src/lib/SequencePanel.svelte

@@ -17,15 +17,16 @@
 
   async function save() {
     if (!seq) return;
-    const s = seq.slot;
-    const n = name;
-    const b = Number(bpm);
-    const l = Number(bars);
-    if (n === seq.name && b === seq.bpm && l === seq.bars) return;
-    if (seq.hasNotes && l < seq.bars) {
+    // Copied before any await: props are live and may change meanwhile.
+    const slot = seq.slot;
+    const newName = name;
+    const newBpm = Number(bpm);
+    const newBars = Number(bars);
+    if (newName === seq.name && newBpm === seq.bpm && newBars === seq.bars) return;
+    if (seq.hasNotes && newBars < seq.bars) {
       const ok = await confirm({
         title: "Shorten a sequence with notes?",
-        message: `${seq.name} has recorded notes. Notes after bar ${l} will not play, but they are kept: lengthening the sequence again brings them back.`,
+        message: `${seq.name} has recorded notes. Notes after bar ${newBars} will not play, but they are kept: lengthening the sequence again brings them back.`,
         items: [],
         action: "Shorten",
       });
@@ -34,10 +35,10 @@
         return;
       }
     }
-    await run(() => Service.SetSequence(s, n, b, l));
+    await run(() => Service.SetSequence(slot, newName, newBpm, newBars));
     // run() replaced the state; if Go refused, the fields still hold the
     // typed values, so put the stored ones back.
-    const now = app.state?.sequences?.find((q) => q.slot === s);
+    const now = app.state?.sequences?.find((q) => q.slot === slot);
     if (now) {
       name = now.name;
       bpm = now.bpm;
@@ -47,14 +48,14 @@
 
   async function remove() {
     if (!seq) return;
-    const s = seq.slot;
+    const slot = seq.slot; // copied before the await, as in save()
     const ok = await confirm({
       title: `Remove ${seq.name}?`,
       message: seq.hasNotes ? "Its recorded notes will be deleted too." : "The sequence has no recorded notes.",
       items: [],
       action: "Remove",
     });
-    if (ok) await run(() => Service.RemoveSequence(s));
+    if (ok) await run(() => Service.RemoveSequence(slot));
   }
 
   function enter(e: KeyboardEvent) {