rework player store and add global player context

This commit is contained in:
jeffvli
2025-11-02 01:09:40 -07:00
parent b35b805a8e
commit 1d4069d4fa
4 changed files with 1484 additions and 1089 deletions
+15
View File
@@ -0,0 +1,15 @@
import type { StoreApi, UseBoundStore } from 'zustand';
type WithSelectors<S> = S extends { getState: () => infer T }
? S & { use: { [K in keyof T]: () => T[K] } }
: never;
export const createSelectors = <S extends UseBoundStore<StoreApi<object>>>(_store: S) => {
const store = _store as WithSelectors<typeof _store>;
store.use = {};
for (const k of Object.keys(store.getState())) {
(store.use as any)[k] = () => store((s) => s[k as keyof typeof s]);
}
return store;
};