emitCause method

void emitCause(
  1. String description, {
  2. Map<String, dynamic>? metadata,
  3. CausalEventType type = CausalEventType.stateChange,
})

Emit a causal event linked to the current CausalityZone context.

description should be a human-readable label like 'cart_item_added'. metadata can contain any JSON-safe data relevant to the mutation. type defaults to CausalEventType.stateChange.

Implementation

void emitCause(
  String description, {
  Map<String, dynamic>? metadata,
  CausalEventType type = CausalEventType.stateChange,
}) {
  assert(() {
    final context = CausalityZone.currentContext();
    TrinityEventBus.instance.emit(CausalEvent(
      parentId: context?.eventId,
      type: type,
      description: '$runtimeType: $description',
      metadata: metadata ?? const {},
    ));
    return true;
  }());
}