Restructured project from nested workspace pattern to flat single-repo layout. This eliminates redundant nesting and consolidates all project files under version control. ## Migration Summary **Before:** ``` alex/ (workspace, not versioned) ├── chess-game/ (git repo) │ ├── js/, css/, tests/ │ └── index.html └── docs/ (planning, not versioned) ``` **After:** ``` alex/ (git repo, everything versioned) ├── js/, css/, tests/ ├── index.html ├── docs/ (project documentation) ├── planning/ (historical planning docs) ├── .gitea/ (CI/CD) └── CLAUDE.md (configuration) ``` ## Changes Made ### Structure Consolidation - Moved all chess-game/ contents to root level - Removed redundant chess-game/ subdirectory - Flattened directory structure (eliminated one nesting level) ### Documentation Organization - Moved chess-game/docs/ → docs/ (project documentation) - Moved alex/docs/ → planning/ (historical planning documents) - Added CLAUDE.md (workspace configuration) - Added IMPLEMENTATION_PROMPT.md (original project prompt) ### Version Control Improvements - All project files now under version control - Planning documents preserved in planning/ folder - Merged .gitignore files (workspace + project) - Added .claude/ agent configurations ### File Updates - Updated .gitignore to include both workspace and project excludes - Moved README.md to root level - All import paths remain functional (relative paths unchanged) ## Benefits ✅ **Simpler Structure** - One level of nesting removed ✅ **Complete Versioning** - All documentation now in git ✅ **Standard Layout** - Matches open-source project conventions ✅ **Easier Navigation** - Direct access to all project files ✅ **CI/CD Compatible** - All workflows still functional ## Technical Validation - ✅ Node.js environment verified - ✅ Dependencies installed successfully - ✅ Dev server starts and responds - ✅ All core files present and accessible - ✅ Git repository functional ## Files Preserved **Implementation Files:** - js/ (3,517 lines of code) - css/ (4 stylesheets) - tests/ (87 test cases) - index.html - package.json **CI/CD Pipeline:** - .gitea/workflows/ci.yml - .gitea/workflows/release.yml **Documentation:** - docs/ (12+ documentation files) - planning/ (historical planning materials) - README.md **Configuration:** - jest.config.js, babel.config.cjs, playwright.config.js - .gitignore (merged) - CLAUDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
140 lines
3.3 KiB
JavaScript
140 lines
3.3 KiB
JavaScript
/**
|
|
* @file EventBus.js
|
|
* @description Simple event bus for component communication
|
|
* @author Implementation Team
|
|
*/
|
|
|
|
/**
|
|
* @class EventBus
|
|
* @description Facilitates publish-subscribe pattern for loose coupling between components
|
|
*
|
|
* @example
|
|
* const eventBus = new EventBus();
|
|
* eventBus.subscribe('piece:moved', (data) => console.log(data));
|
|
* eventBus.publish('piece:moved', {from: 'e2', to: 'e4'});
|
|
*/
|
|
class EventBus {
|
|
constructor() {
|
|
/**
|
|
* @property {Map} _subscribers - Map of event names to arrays of callbacks
|
|
*/
|
|
this._subscribers = new Map();
|
|
}
|
|
|
|
/**
|
|
* Subscribe to an event
|
|
*
|
|
* @param {string} event - Event name
|
|
* @param {Function} callback - Function to call when event is published
|
|
* @returns {Function} Unsubscribe function
|
|
*
|
|
* @example
|
|
* const unsubscribe = eventBus.subscribe('game:check', handleCheck);
|
|
* // Later: unsubscribe()
|
|
*/
|
|
subscribe(event, callback) {
|
|
// TODO: Implement subscription
|
|
// 1. Check if event exists in _subscribers
|
|
// 2. If not, create new array for this event
|
|
// 3. Add callback to array
|
|
// 4. Return unsubscribe function that removes this callback
|
|
|
|
// Return unsubscribe function
|
|
return () => {
|
|
// TODO: Implement unsubscribe logic
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Publish an event with data
|
|
*
|
|
* @param {string} event - Event name
|
|
* @param {*} data - Data to pass to subscribers
|
|
*
|
|
* @example
|
|
* eventBus.publish('piece:moved', {
|
|
* piece: pawn,
|
|
* from: {row: 6, col: 4},
|
|
* to: {row: 4, col: 4}
|
|
* });
|
|
*/
|
|
publish(event, data) {
|
|
// TODO: Implement publishing
|
|
// 1. Get all subscribers for this event
|
|
// 2. Call each callback with the data
|
|
// 3. Handle any errors in callbacks (try-catch)
|
|
}
|
|
|
|
/**
|
|
* Unsubscribe a specific callback from an event
|
|
*
|
|
* @param {string} event - Event name
|
|
* @param {Function} callback - Callback to remove
|
|
*
|
|
* @example
|
|
* eventBus.unsubscribe('game:check', handleCheck);
|
|
*/
|
|
unsubscribe(event, callback) {
|
|
// TODO: Implement unsubscribe
|
|
// 1. Get subscribers for event
|
|
// 2. Find and remove the callback
|
|
}
|
|
|
|
/**
|
|
* Remove all subscribers for an event
|
|
*
|
|
* @param {string} event - Event name
|
|
*
|
|
* @example
|
|
* eventBus.clear('game:over');
|
|
*/
|
|
clear(event) {
|
|
// TODO: Implement clear
|
|
// Remove all subscribers for the event
|
|
}
|
|
|
|
/**
|
|
* Remove all subscribers for all events
|
|
*
|
|
* @example
|
|
* eventBus.clearAll();
|
|
*/
|
|
clearAll() {
|
|
// TODO: Implement clear all
|
|
this._subscribers.clear();
|
|
}
|
|
|
|
/**
|
|
* Get count of subscribers for an event
|
|
*
|
|
* @param {string} event - Event name
|
|
* @returns {number} Number of subscribers
|
|
*
|
|
* @example
|
|
* const count = eventBus.getSubscriberCount('piece:moved');
|
|
*/
|
|
getSubscriberCount(event) {
|
|
// TODO: Implement subscriber count
|
|
return 0; // Replace with actual logic
|
|
}
|
|
|
|
/**
|
|
* Check if an event has any subscribers
|
|
*
|
|
* @param {string} event - Event name
|
|
* @returns {boolean} True if event has subscribers
|
|
*
|
|
* @example
|
|
* if (eventBus.hasSubscribers('game:over')) {
|
|
* // Do something
|
|
* }
|
|
*/
|
|
hasSubscribers(event) {
|
|
// TODO: Implement has subscribers check
|
|
return false; // Replace with actual logic
|
|
}
|
|
}
|
|
|
|
// Export singleton instance
|
|
export default new EventBus();
|