mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 10:29:35 +08:00
0221855ba7
Classic Ember components (i.e. "@ember/component") rely upon "event delegation" to listen for events at the application root and then dispatch those events to any event handlers defined on individual Classic components. This coordination is handled by Ember's EventDispatcher. In contrast, Glimmer components (i.e. "@glimmer/component") expect event listeners to be added to elements using modifiers (such as `{{on "click"}}`). These event listeners are added directly to DOM elements using `addEventListener`. There is no need for an event dispatcher. Issues may arise when using Classic and Glimmer components together, since it requires reconciling the two event handling approaches. For instance, event propagation may not work as expected when a Classic component is nested inside a Glimmer component. `normalizeEmberEventHandling` helps an application standardize upon the Glimmer event handling approach by eliminating usage of event delegation and instead rewiring Classic components to directly use `addEventListener`. Specifically, it performs the following: - Invokes `eliminateClassicEventDelegation()` to remove all events associated with Ember's EventDispatcher to reduce its runtime overhead and ensure that it is effectively not in use. - Invokes `rewireClassicComponentEvents(app)` to rewire each Classic component to add its own event listeners for standard event handlers (e.g. `click`, `mouseDown`, `submit`, etc.). - Configures an instance initializer that invokes `rewireActionModifier(appInstance)` to redefine the `action` modifier with a substitute that uses `addEventListener`. Additional changes include: * d-button: only preventDefault / stopPropagation for handled actions This allows unhandled events to propagate as expected. * d-editor: avoid adding duplicate event listener for tests This extra event listener causes duplicate paste events in tests. * group-manage-email-settings: Monitor `input` instead of `change` event for checkboxes |
||
---|---|---|
.. | ||
assets | ||
controllers | ||
helpers | ||
jobs | ||
mailers | ||
models | ||
serializers | ||
services | ||
views |