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:
parent
c97c2c4150
commit
a92b889dfa
|
|
@ -10,6 +10,7 @@ import {
|
||||||
Transform2D,
|
Transform2D,
|
||||||
validatePlacement,
|
validatePlacement,
|
||||||
} from "boardgame-core/samples/slay-the-spire-like";
|
} from "boardgame-core/samples/slay-the-spire-like";
|
||||||
|
import { batch } from "@preact/signals-core";
|
||||||
|
|
||||||
function genId() {
|
function genId() {
|
||||||
return Math.random().toString(16).slice(-8);
|
return Math.random().toString(16).slice(-8);
|
||||||
|
|
@ -62,13 +63,15 @@ export function moveItem(
|
||||||
const validation = validatePlacement(removed, item.shape, newTransform);
|
const validation = validatePlacement(removed, item.shape, newTransform);
|
||||||
if (!validation.valid) return false;
|
if (!validation.valid) return false;
|
||||||
|
|
||||||
from.produce((inv) => {
|
batch(() => {
|
||||||
removeItemFromGrid(inv, itemId);
|
from.produce((inv) => {
|
||||||
});
|
removeItemFromGrid(inv, itemId);
|
||||||
to.produce((inv) => {
|
});
|
||||||
placeItem(inv, {
|
to.produce((inv) => {
|
||||||
...item,
|
placeItem(inv, {
|
||||||
transform: newTransform,
|
...item,
|
||||||
|
transform: newTransform,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue