UseEvent<T extends Object?> class
A hook that manages events.
Allows to handle event of instance wherever. Using it with the instance directly:
UseEvent.withInstance(appContext);
or using it with T
instance
that it to has been registed with ReactterInstanceManager:
UseEvent<AppContext>();
if it has a id
:
UseEvent<AppContext>('uniqueId');
You can listen to event using on method:
enum Events { SomeEvent };
void _onSomeEvent(inst, param) {
print("$inst's Events.SomeEvent emitted with param: $param.");
}
UseEvent<AppContext>().on(Events.SomeEvent, _onSomeEvent);
use off method to stop listening event:
UseEvent<AppContext>().off(Events.SomeEvent, _onSomeEvent);
If you want to listen to event only once, use one method:
UseEvent<AppContext>().one(Events.SomeEvent, _onSomeEvent);
And use emit method to trigger event:
UseEvent<AppContext>().emit(Events.SomeEvent, 'Parameter');
IMPORTANT: Don't forget to remove event using off or using dispose to remove all instance's events. Failure to do so could increase memory usage or have unexpected behaviors such as events in permanent listening.
See also:
- ReactterInstanceManager, a instances manager.
Constructors
- UseEvent([String? _id])
- UseEvent.withInstance(T instance)
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
-
dispose(
) → void - Removes all instance's events
-
emit(
Enum eventName, [dynamic param]) → void -
Trigger
eventName
event with or without theparam
given. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
off<
P> (Enum eventName, CallbackEvent< T, P> callback) → void -
Removes the
callback
ofeventName
event. -
on<
P extends dynamic> (Enum eventName, CallbackEvent< T, P> callback) → void -
Puts on to listen
eventName
event. -
one<
P> (Enum eventName, CallbackEvent< T, P> callback) → void -
Puts on to listen
eventName
event only once. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited