handleCommand method

  1. @override
Future<List<Event>> handleCommand(
  1. InvoiceState currentState,
  2. Command command
)

Handle a command and generate events This is the core method for command processing

Implementation

@override
Future<List<Event>> handleCommand(InvoiceState currentState, Command command) async {
  return switch (command) {
    final CreateInvoiceCommand cmd => _handleCreateInvoice(currentState, cmd),
    final MarkInvoicePaidCommand cmd => _handleMarkInvoicePaid(currentState, cmd),
    final CancelInvoiceCommand cmd => _handleCancelInvoice(currentState, cmd),
    final ExpireInvoiceCommand cmd => _handleExpireInvoice(currentState, cmd),
    _ => throw ArgumentError('Unknown command type: ${command.runtimeType}'),
  };
}