DEV: Ensure event-handling reopens are only performed once (#18722)
In test mode we reinitialize the Application for every test. We only want to apply the class reopens once to avoid performance regressions and memory leaks in the test suite.
This commit is contained in:
parent
28be5d3037
commit
fcb4675415
|
@ -2,6 +2,7 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
import { actionModifier } from "./ember-action-modifier";
|
import { actionModifier } from "./ember-action-modifier";
|
||||||
|
import Ember from "ember";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classic Ember components (i.e. "@ember/component") rely upon "event
|
* Classic Ember components (i.e. "@ember/component") rely upon "event
|
||||||
|
@ -48,12 +49,17 @@ export function normalizeEmberEventHandling(app) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let eliminatedClassicEventDelegation = false;
|
||||||
/**
|
/**
|
||||||
* Remove all events registered with Ember's EventDispatcher to reduce its
|
* Remove all events registered with Ember's EventDispatcher to reduce its
|
||||||
* runtime overhead.
|
* runtime overhead.
|
||||||
*/
|
*/
|
||||||
function eliminateClassicEventDelegation() {
|
function eliminateClassicEventDelegation() {
|
||||||
// eslint-disable-next-line no-undef
|
if (eliminatedClassicEventDelegation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
eliminatedClassicEventDelegation = true;
|
||||||
|
|
||||||
Ember.EventDispatcher.reopen({
|
Ember.EventDispatcher.reopen({
|
||||||
events: {},
|
events: {},
|
||||||
});
|
});
|
||||||
|
@ -100,6 +106,7 @@ const COMPONENT_SETUP = new WeakMap();
|
||||||
|
|
||||||
const INTERNAL = Symbol("INTERNAL");
|
const INTERNAL = Symbol("INTERNAL");
|
||||||
|
|
||||||
|
let rewireDone = false;
|
||||||
/**
|
/**
|
||||||
* Rewires classic component event handling to use `addEventListener` directly
|
* Rewires classic component event handling to use `addEventListener` directly
|
||||||
* on inserted elements, instead of relying upon classic event delegation.
|
* on inserted elements, instead of relying upon classic event delegation.
|
||||||
|
@ -112,6 +119,11 @@ const INTERNAL = Symbol("INTERNAL");
|
||||||
* @param {Application} app
|
* @param {Application} app
|
||||||
*/
|
*/
|
||||||
function rewireClassicComponentEvents(app) {
|
function rewireClassicComponentEvents(app) {
|
||||||
|
if (rewireDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rewireDone = true;
|
||||||
|
|
||||||
const allEvents = { ...EVENTS };
|
const allEvents = { ...EVENTS };
|
||||||
|
|
||||||
if (app.customEvents) {
|
if (app.customEvents) {
|
||||||
|
|
Loading…
Reference in New Issue