Add UI improvements + refactor frontend to event-driven architecture
Some checks failed
CI / ci (push) Failing after 1m9s
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).
This commit is contained in:
20
painter-js/src/domain/app-state.js
Normal file
20
painter-js/src/domain/app-state.js
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user