Skip to content

Dispatch events with both CustomEvent and jQuery#3185

Open
TiTidom-RC wants to merge 1 commit into
jeedom:developfrom
TiTidom-RC:native-customevent-for-plugins
Open

Dispatch events with both CustomEvent and jQuery#3185
TiTidom-RC wants to merge 1 commit into
jeedom:developfrom
TiTidom-RC:native-customevent-for-plugins

Conversation

@TiTidom-RC

Copy link
Copy Markdown
Contributor

Description

Problem
Currently, only core Jeedom events (hardcoded list) can use [dispatchEvent] (native CustomEvent). Plugins are forced to use jQuery only.

Solution
Removed the restricted event list. All events (core and plugins) now use :

  • [dispatchEvent] : for all events (native standard)
  • jQuery [trigger] : maintained for events with data (backward compatibility, like before)

Events are now dispatched using both the native CustomEvent API and jQuery's trigger for backward compatibility. This ensures that all listeners, regardless of implementation, receive the events.

Suggested changelog entry

Support natif des CustomEvent pour les plugins

Related issues/external references

Fixes #

Types of changes

  • Bug fix (non-breaking change which fixes)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

Events are now dispatched using both the native CustomEvent API and jQuery's trigger for backward compatibility. This ensures that all listeners, regardless of implementation, receive the events.
@zoic21 zoic21 requested a review from Salvialf January 30, 2026 10:09
@Salvialf Salvialf deleted the branch jeedom:develop March 31, 2026 17:44
@Salvialf Salvialf closed this Mar 31, 2026
@Salvialf Salvialf reopened this Mar 31, 2026
@NebzHB

NebzHB commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Hello, maybe add a subscription system or something ? to not overflood listeners ?

@Salvialf

Salvialf commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Hello,

Dispatching both natively and via jQuery for the same event risks more than just duplicate execution, the two firings wouldn't even behave consistently. jQuery's .on() already registers a real addEventListener under the hood, so the native dispatchEvent() alone already reaches jQuery-bound handlers, but without the data in the handler's expected second argument, it lands in event.originalEvent.detail instead. The explicit .trigger() call right after then fires the same handler a second time, this time with the data where jQuery-based code actually expects it. So a jQuery-based listener would run twice, with the first run likely receiving undefined where it expects its data.

Given it'll probably take a long time before every plugin has migrated its listeners to vanilla JS, an opt-in path seems safer than a blanket switch: keep an extensible jeedom.vanillaEvents array, and only skip the jQuery .trigger() for event names a plugin explicitly registers into it once its own JS has fully moved to addEventListener. Everything else keeps the current jQuery-based behavior unchanged. See #3416 for the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants