1681-engine / ui / Store
Interface: Store<T> ​
Defined in: src/ui/dom/createStore.ts:8
A tiny shared state store between the game and its UI, framework-free. Same shape as the engine's settings store and as zustand's vanilla stores (getState, setState, subscribe), so React reads it with useSyncExternalStore(store.subscribe, store.getState).
Type Parameters ​
| Type Parameter |
|---|
T extends object |
Methods ​
getState() ​
getState(): T;Defined in: src/ui/dom/createStore.ts:9
Returns ​
T
reset() ​
reset(): void;Defined in: src/ui/dom/createStore.ts:20
Back to the state it was made with.
Returns ​
void
select() ​
select<S>(
select,
listener,
equals?
): () => void;Defined in: src/ui/dom/createStore.ts:18
Calls listener only when select(state) changes (by equals, default Object.is).
Type Parameters ​
| Type Parameter |
|---|
S |
Parameters ​
| Parameter | Type |
|---|---|
select | (state) => S |
listener | (value, previous) => void |
equals? | (a, b) => boolean |
Returns ​
() => void
setState() ​
setState(patch): void;Defined in: src/ui/dom/createStore.ts:14
Merges a patch (or what a function of the state returns) into a new state object. A patch that changes nothing notifies nobody: a game may set the player's health every frame and the UI renders only when it moved.
Parameters ​
| Parameter | Type |
|---|---|
patch | Partial<T> | ((state) => Partial<T>) |
Returns ​
void
subscribe() ​
subscribe(listener): () => void;Defined in: src/ui/dom/createStore.ts:16
Calls listener after every change; the returned function unsubscribes.
Parameters ​
| Parameter | Type |
|---|---|
listener | StoreListener<T> |
Returns ​
() => void