MPS class
A publish-subscribe event system that allows communication between different parts of an application.
This class provides a mechanism for registering callbacks (subscribing) to named events, and triggering those callbacks (publishing) when the named event is emitted. Callbacks can be registered to listen for the named event indefinitely, or just once. The system can also keep track of the number of callbacks registered for each event. Concept taken from the JS library. it has duplicated implemntation between
- subscribe = on
- unsubscribe = off
- publish = emit
- publish(N) = emit(N) Accepts a "once()" event like signals.
Constructors
- MPS()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
count(
String topic) → int -
Get the number of subscriptions for a
topic
in the event system. -
countOnce(
String topic) → int -
Get the number of one-time subscriptions for a
topic
in the event system. -
emit(
String topic) → MPS -
Emits a signal to all subscribed functions for a
topic
in the event system. This method calls all functions subscribed to the topic with no arguments. Any errors thrown by the functions are silently ignored. -
emit1<
T> (String topic, T arg1) → void -
Emits a signal to all subscribed functions for a
topic
in the event system. This method calls all functions subscribed to the topic with one argumentarg1
. Any errors thrown by the functions are silently ignored. -
emit2<
T, S> (String topic, T arg1, S arg2) → void -
Emits a signal to all subscribed functions for a
topic
in the event system. This method calls all functions subscribed to the topic with two arguments. Any errors thrown by the functions are silently ignored. -
emit3<
A, B, C> (String topic, A arg1, B arg2, C arg3) → void -
Emits a signal to all subscribed functions for a
topic
in the event system. This method calls all functions subscribed to the topic with three arguments. Any errors thrown by the functions are silently ignored. -
emitParams(
String topic, CallbackParams args) → void -
Emits an event with the given
topic
andargs
to all subscribed callbacks. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
off(
String topic, Function? callback) → void -
Remove a specific
callback
from atopic
's subscription list in the event system. If the function is in the list, removes it from the subscription and one-time subscription lists. -
offAll(
String event) → bool -
Removes all callbacks subscribed to the given
event
. -
on(
String topic, Function? callback) → MPS -
Subscribe a function to a
topic
in the event system. If thecallback
is not already subscribed, adds it to the subscription list. Returns true if the function was added to the list, false if it was already subscribed. -
once(
String topic, Function callback) → bool -
Registers a callback to listen for the specified event
topic
. Thecallback
will only be called once for this event. -
publish(
String topic) → void -
Publishes the specified event
topic
to all registered callbacks for that event without any arguments. -
publish1<
T> (String topic, T arg1) → void -
Publishes the specified event
topic
along with the givenarg1
(argument) to all registered callbacks for that event. -
publish2<
T, S> (String topic, T arg1, S arg2) → void -
Publishes the specified event
topic
along with the given argumentsarg1
andarg2
to all registered callbacks for that event. -
publishParams(
String topic, CallbackParams args) → void -
Publishes the specified
topic
along with the given CallbackParams to all registered callbacks for thattopic
. -
subscribe(
String topic, Function callback) → bool -
Registers a
callback
to listen for the specified eventtopic
. -
toString(
) → String -
A string representation of this object.
override
-
unsubscribe(
String topic, Function callback) → bool -
Unregisters the specified
callback
from the specified eventtopic
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited