feat(sts-like-viewer): batch inventory item movement

Wrap item removal and placement in a batch to prevent multiple
reactive updates when moving items between inventories.
This commit is contained in:
hypercross 2026-04-21 16:50:48 +08:00
parent c97c2c4150
commit a92b889dfa
1 changed files with 10 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import {
Transform2D,
validatePlacement,
} from "boardgame-core/samples/slay-the-spire-like";
import { batch } from "@preact/signals-core";
function genId() {
return Math.random().toString(16).slice(-8);
@ -62,6 +63,7 @@ export function moveItem(
const validation = validatePlacement(removed, item.shape, newTransform);
if (!validation.valid) return false;
batch(() => {
from.produce((inv) => {
removeItemFromGrid(inv, itemId);
});
@ -71,6 +73,7 @@ export function moveItem(
transform: newTransform,
});
});
});
return true;
}