Package com.j3d.engine.react.events
Events
The engine, in most cases instead of trying to finder a specific class instance and method to call, makes use of "events" which allow any parts of the engine to fire events to any other part at any time of execution.
Any class which extends EventEmitter inherits event emitting
capabilities to any class which it attaches that implements EventListener.
Classes which cannot directly extends EventEmitter can instead implement EventEmitterInterface
and hence use the generic static utilities provided by EventEmitter
such as to still emit events.
An event is broadcast with an EventPayload to all attached listeners.
This class can also be the superclass of concrete implementations, and it's up to the listener to
decipher the payload. However, there is also a EventType enum
where all event types can be categorised by a single enum before performing type casting.
Classes and interfaces
-
An
EventEmitteris a class that allows other classes to register as listeners and receive events.The
EventEmitterInterfaceis an interface that allows classes that cannot extendEventEmitterto still emit events using its static utility methods. -
An
EventListeneris an interface which defines any class as one that can listen for events and handle said events viaEventListener.onEvent(com.j3d.engine.react.events.EventType, com.j3d.engine.react.events.EventPayload)An
EventReactoris a special type ofEventListenerwhich is removed after it has received it's event. It "reacts" to the event once and is removed thereafter.An
IdempotentEventListeneris a special type ofEventListenerthat guarantees that processing the same event multiple times will produce the same result as processing it once. This is useful for events that might be re-triggered or re-broadcast, ensuring consistent state. -
An
EventPayloadis a class that carries data related to an event. It can be extended to provide specific event data. -
An
EventTypeis an enum that categorises different types of events, allowing listeners to filter and handle specific event types.
- Author:
- Lehlogonolo Poole
-
ClassDescriptionEventEmitter is a class that allows for other classes to attach events that they can broadcast to at any time.EventEmitterInterface is an interface that allows for other classes to attach events that they can broadcast to at any time.EventListener is an interface which just allows Objects to listen for incoming Events at any time.EventPayload<T>EventPayload is an abstract class which is used to represent the properties that the called event may input and or return.An interface which only reacts to a single event and later gets removed.Events is an enum that describes the possible Events that a listener can listen for.A simple interface for implementors to use such that they dont bloat some specific setting due to multiple events firing that do the same thing.