feat: optimized state handling

This commit is contained in:
TrèsAbhi committed 2024-01-13 13:44:27 -06:00
1 parent 033d361cea
commit 230b2df5fd
6 files changed
+145 -186

No files matched your search

+26 -23
View File
@@ -1,5 +1,6 @@
import { produce } from 'immer';
import { create } from 'zustand';
import { subscribeWithSelector } from 'zustand/middleware';
import { TankType, TreeTypeString } from '../components/Tanks';
import {
GunDefinition,
@@ -54,29 +55,31 @@ type Tankopedia = {
| { areTanksAssigned: false }
);
export const useTankopedia = create<Tankopedia>()(() => ({
sort: {
by: 'tier',
direction: 'descending',
},
filters: {
tiers: [],
types: [],
treeTypes: [],
nations: [],
test: 'include',
},
model: {
gunPitch: 0,
hullYaw: 0,
turretYaw: 0,
controlsEnabled: true,
showGrid: true,
showSpacedArmor: true,
},
areTanksAssigned: false,
mode: 'model',
}));
export const useTankopedia = create<Tankopedia>()(
subscribeWithSelector<Tankopedia>(() => ({
sort: {
by: 'tier',
direction: 'descending',
},
filters: {
tiers: [],
types: [],
treeTypes: [],
nations: [],
test: 'include',
},
model: {
gunPitch: 0,
hullYaw: 0,
turretYaw: 0,
controlsEnabled: true,
showGrid: true,
showSpacedArmor: true,
},
areTanksAssigned: false,
mode: 'model',
})),
);
export default function mutateTankopedia(recipe: (draft: Tankopedia) => void) {
useTankopedia.setState(produce(recipe));