EventBus class
EventBus is a stream based solution to remove dependencies between elements.
Usage:
final bus = EventBus([
EventTransformer(HeightProvidedEvent, (event, eventBus) => BmiCalculatedEvent()),
EventTransformer(WeightProvidedEvent, (event, eventBus) => BmiCalculatedEvent()),
]);
bus.publish(WeightProvidedEvent());
final outputStream = bus.select<BmiCalculatedEvent>();
You can now listen to the outputStream
TODO: Find a way to check circular transformations and remove them.
- Annotations
-
- @immutable
Constructors
-
EventBus([List<
EventTransformer< ? transformers])Object, Object> > - EventBus will start listening to events when constructed.
- EventBus.from(EventBus other)
- Creates a copy from another bus.
-
EventBus.withLogger([List<
EventTransformer< ? transformers])Object, Object> > -
Creates an EventBus with logging ability.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- store → Store
-
Events are stored here.
final
-
stream
→ Stream<
Object> -
The internal stream is exposed for customized listening.
no setter
-
transformers
→ Iterable<
EventTransformer< Object, Object> > -
A list of transformers extracted from transformerMap.
no setter
Methods
-
cancelFromStream(
String id) → EventBus -
dispose(
) → Future< void> -
Disposes the
SubscriptionManager
. Closes theStreamController
. Unregisters all theTransformers
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
publish(
Object message) → EventBus - Publishes a single message.
-
publishAndSave(
Object message) → EventBus - Publishes and saves messages to store.
-
publishAndSaveFromFuture(
Future< Object> future) → EventBus - Publishes and saves the message after resolving a future.
-
publishAndSaveFromStream(
Stream< Object> stream, String id) → EventBus - Publishes and saves messages as the stream emits.
-
publishAndSaveMany(
Iterable< Object> messageList) → EventBus - Publishes and saves multiple messages.
-
publishFromFuture(
Future< Object> future) → EventBus - Publishes the message after resolving a future.
-
publishFromStore<
T extends Object> () → EventBus - Publishes a message from store.
-
publishFromStream(
Stream< Object> stream, String id) → EventBus - Publishes messages as the stream emits.
-
publishMany(
Iterable< Object> messageList) → EventBus - Publishes multiple messages.
-
registerTransformers(
List< EventTransformer< transformers) → EventBusObject, Object> > - Registered transformers will run when a source event is hit.
-
save(
Object message) → EventBus - Saves message to store.
-
select<
T extends Object> () → Stream< T> -
Selects a message of type
T
. -
selectFromStore<
T extends Object> () → T -
Selects a message of type
T
from store. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited