Some checks failed
CI / ci (push) Failing after 1m9s
Features: disabled place button during cooldown, beep on cooldown end, hand/paint mode toggle with Space shortcut, soldier count pop animation. Architecture: centralized DOM refs, AppState store replacing localStorage polling, event bus decoupling socket from handlers, keyboard manager, tool manager with Strategy pattern (paint-tool, hand-tool).
21 lines
514 B
JavaScript
21 lines
514 B
JavaScript
export const createAppState = (initial) => {
|
|
const state = { ...initial };
|
|
const listeners = {};
|
|
|
|
return {
|
|
get: (key) => state[key],
|
|
set: (key, value) => {
|
|
const old = state[key];
|
|
state[key] = value;
|
|
(listeners[key] || []).forEach((fn) => fn(value, old));
|
|
},
|
|
subscribe: (key, fn) => {
|
|
if (!listeners[key]) listeners[key] = [];
|
|
listeners[key].push(fn);
|
|
return () => {
|
|
listeners[key] = listeners[key].filter((f) => f !== fn);
|
|
};
|
|
},
|
|
};
|
|
};
|