CircuitService

Application/Services~ CircuitService

new CircuitService()

🔧 Primary Extension API - Circuit Operations

CircuitService is the main application service that developers will interact with to programmatically manipulate circuits.

Description:
  • 🔧 Primary Extension API - Circuit Operations

    CircuitService is the main application service that developers will interact with to programmatically manipulate circuits. It provides a clean, event-driven API for all circuit operations while maintaining domain integrity.

    Key Features:

    • Event-driven architecture with real-time GUI updates
    • Domain validation and business rule enforcement
    • Element lifecycle management (add, update, delete)
    • Circuit state serialization and persistence
    • Undo/redo support through state management

    Events Emitted:

    • elementAdded: When a new element is added
    • elementDeleted: When an element is removed
    • elementUpdated: When element properties change
    • update: General circuit state change notification
Source:
Examples
// Basic circuit manipulation
const service = new CircuitService(new Circuit());

// Listen for changes
service.on('elementAdded', (element) => {
  console.log(`Added ${element.type} ${element.id}`);
});

// Add elements
const resistor = new Resistor('R1', [pos1, pos2], null, new Properties({resistance: 1000}));
service.addElement(resistor);
// Advanced usage with properties
service.updateElementProperties('R1', {
  resistance: 2200,
  label: 'Main Resistor'
});

const serialized = service.exportState();
service.importState(serialized);

Extends

  • EventEmitter