refactor(core): extract core modules (state, persistence, config, events)
Extract core system modules from monolithic index.js into modular architecture: - src/core/state.js: All extension state variables with controlled setters - src/core/persistence.js: Settings and chat data persistence functions - src/core/config.js: Extension metadata and default configuration - src/core/events.js: SillyTavern event system wrapper Updated index.js to import and use new core modules. Removed ~220 lines of state/persistence code from index.js. Part of Epic 1: Foundation & Core Systems (Phase 1.1-1.2)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Core Events Module
|
||||
* Wrapper for SillyTavern event system
|
||||
*/
|
||||
|
||||
import { eventSource, event_types } from '../../../../../../script.js';
|
||||
|
||||
/**
|
||||
* Register an event handler
|
||||
* @param {string} eventType - Event type from event_types
|
||||
* @param {Function} handler - Event handler function
|
||||
*/
|
||||
export function on(eventType, handler) {
|
||||
eventSource.on(eventType, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a one-time event handler
|
||||
* @param {string} eventType - Event type from event_types
|
||||
* @param {Function} handler - Event handler function
|
||||
*/
|
||||
export function once(eventType, handler) {
|
||||
eventSource.once(eventType, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an event handler
|
||||
* @param {string} eventType - Event type from event_types
|
||||
* @param {Function} handler - Event handler function to remove
|
||||
*/
|
||||
export function off(eventType, handler) {
|
||||
eventSource.off(eventType, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit an event
|
||||
* @param {string} eventType - Event type to emit
|
||||
* @param {...*} args - Arguments to pass to handlers
|
||||
*/
|
||||
export function emit(eventType, ...args) {
|
||||
eventSource.emit(eventType, ...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-export event types for convenience
|
||||
*/
|
||||
export { event_types };
|
||||
Reference in New Issue
Block a user