Files
painter/painter-js/src/domain/app-state.js
Gabriel Kaszewski dc6bff027a
Some checks failed
CI / ci (push) Failing after 1m9s
Add UI improvements + refactor frontend to event-driven architecture
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).
2026-08-18 10:49:16 +02:00

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);
};
},
};
};