emitCause method
void
emitCause(
- String description, {
- Map<
String, dynamic> ? metadata, - 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;
}());
}