Event Handler
Esta página aún no está disponible en tu idioma.
In Reactter, event handler plays a pivotal role in facilitating seamless communication and coordination between various components within the application. Designed to ensure efficient state management and dependency injection, fostering a cohesive ecosystem where different parts of the application can interact harmoniously.
API
Reactter offers the following event handler mechanisms:
How it works
Event handler in Reactter is based on a few fundamental concepts:
- Event: Is a enum that represents a specific action or occurrence in the application.
- Instance: Is an object that emits and listens to events.
- Listener: Is a function that is executed when an event is emitted.
Understanding these concepts is crucial for effectively managing event-driven interactions in Reactter apps.
Example
To illustrate this, let’s take a countdown example seen from the State Management page:
In this example, the line 10 to 14, we see that the Rt.on
method is used to subscribe to the Lifecycle.didUpdate
event of the count
instance.
Whenever the count
state changes, the listener function is invoked, printing the current value
of the count
state.
Here, we can’t see the emitter, because it’s encapsulated within the Signal
class, and it’s called when the value
of the count
state changes.
This mechanism is made possible by the underlying state management system.
Now, we do a small tweak to add an emitter:
We added a new event called CustomEvent.countdownFinished
and a new listener that prints a message when the countdown is finished.
When the countdown reaches 0
, the count
instance emits the CustomEvent.countdownFinished
event, and the listener function is invoked, printing the message.
This example demonstrates how the event handler system in Reactter enables seamless communication between different parts of the application, facilitating efficient coordination and interaction.