Skip to content

Conversation

@EHandtkeBasis
Copy link
Member

No description provided.

- Always remove listeners when they're no longer needed to avoid memory leaks.
- Use the provided event payload methods to access event data efficiently, avoiding unnecessary client-server round-trips.
- Prefer using component APIs for event handling unless you have advanced requirements.
- Use registration options (payload, debounce, filter) to optimize performance and event data handling.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [vale] reported by reviewdog 🐶
[webforJ.BeDirect] Avoid using 'optimize performance and event'. Focus more on explicitly giving details about the feature.

@hyyan hyyan added this to the 25.03 milestone Aug 4, 2025
@hyyan hyyan linked an issue Aug 27, 2025 that may be closed by this pull request
@hyyan hyyan removed this from the 25.03 milestone Aug 27, 2025
@EHandtkeBasis EHandtkeBasis marked this pull request as ready for review September 4, 2025 08:26
Comment on lines 23 to 33
## Event dispatcher APIs

[`EventDispatcher`](https://webforj.com/javadoc/com/webforj/dispatcher/EventDispatcher.html) is a minimalistic event manager for dispatching events to listeners. It's not tied to UI components or element events.

**Available methods:**

- `addListener(Class<T> eventClass, EventListener<T> listener)`: Registers a listener for a specific event type. Returns a `ListenerRegistration<T>` for later removal.
- `removeListener(Class<T> eventClass, EventListener<T> listener)`: Removes a specific listener for the given event type.
- `removeAllListeners(Class<T> eventClass)`: Removes all listeners for a given event type.
- `removeAllListeners()`: Removes all listeners from the dispatcher.
- `dispatchEvent(T event)`: Notifies all listeners of the given event.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this section, a list of methods is already available in the Java Docs.

Comment on lines 97 to 101
## Best practices

- Always remove listeners when they're no longer needed to avoid memory leaks.
- Use the provided event payload methods to access event data efficiently.
- Use the EventDispatcher for custom, non-UI event flows. For UI/component events, see the relevant component documentation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first bullet point in the best practices could be expanded upon into it's own section, covering when to remove listeners, how to, and why. Please be specific when writing why removing listeners prevent memory leaks and avoid using a generic "optimizes performance" explanation.

Comment on lines 45 to 49
statusText.setStyle("border", "2px solid #333");
statusText.setStyle("padding", "8px 24px");
statusText.setStyle("border-radius", "var(--dwc-border-radius-s)");
statusText.setStyle("font-size", "var(--dwc-font-size-l)");
statusText.setStyle("background", "var(--dwc-surface-3)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly suggest replacing the multiple setStyle() calls with an InlineStyleSheet annotation and giving the statusText component a class name:

.statusText {
border: 2px solid #333;
border-radius: var(--dwc-border-radius-s);
padding: 8px 24px;
font-size: var(--dwc-font-size-l);
background: var(--dwc-surface-3);
}

Comment on lines 63 to 66
dispatcher.addListener(CustomMessageEvent.class, e -> {
statusText.setText("Received custom event");
button.setEnabled(false);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the dispatcher event can only fire once. Add a way to be able to restart the sample, or create another button that can also fire the dispatcher event with different text.

@hyyan hyyan added the status: waiting-for-review The PR is ready. Waiting for team members to review. label Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-review The PR is ready. Waiting for team members to review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document webforj EventDispatcher system

5 participants