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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user