Add debug logs to EventBus

Events now logs to console when _debug is true:
- [Events.on] event (N handlers) - green
- [Events.off] event - orange
- [Events.emit] event data → N handlers - blue

Toggle in browser console:
  Events._debug = false  // disable
  Events._debug = true   // enable (default)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
ARCHITECT
2026-01-16 19:56:05 +00:00
parent 7672d5582f
commit 66c45910da

View File

@@ -808,12 +808,21 @@ const State = {
// =============================================================================
const Events = {
_handlers: {},
on(event, fn) { (this._handlers[event] ||= []).push(fn); },
_debug: true, // Toggle: Events._debug = false to disable
on(event, fn) {
(this._handlers[event] ||= []).push(fn);
if (this._debug) console.log(`%c[Events.on] ${event}`, 'color: #4CAF50', `(${this._handlers[event].length} handlers)`);
},
off(event, fn) {
if (!fn) delete this._handlers[event];
else this._handlers[event] = (this._handlers[event] || []).filter(h => h !== fn);
if (this._debug) console.log(`%c[Events.off] ${event}`, 'color: #FF9800');
},
emit(event, data) { (this._handlers[event] || []).forEach(fn => fn(data)); }
emit(event, data) {
const handlers = this._handlers[event] || [];
if (this._debug) console.log(`%c[Events.emit] ${event}`, 'color: #7c8aff; font-weight: bold', data !== undefined ? data : '', `${handlers.length} handlers`);
handlers.forEach(fn => fn(data));
}
};
// =============================================================================