Skip to content

Commit

Permalink
refactor(core): Remove global event delegation code. (#57893)
Browse files Browse the repository at this point in the history
This is no longer needed since we are no longer experimenting with it.

PR Close #57893
  • Loading branch information
iteriani authored and alxhub committed Sep 26, 2024
1 parent e40a4fa commit 2e7cfcb
Show file tree
Hide file tree
Showing 19 changed files with 5 additions and 588 deletions.
6 changes: 1 addition & 5 deletions packages/core/src/core_private_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ export {
withI18nSupport as ɵwithI18nSupport,
} from './hydration/api';
export {withEventReplay as ɵwithEventReplay} from './hydration/event_replay';
export {
GLOBAL_EVENT_DELEGATION as ɵGLOBAL_EVENT_DELEGATION,
JSACTION_EVENT_CONTRACT as ɵJSACTION_EVENT_CONTRACT,
} from './event_delegation_utils';
export {provideGlobalEventDelegation as ɵprovideGlobalEventDelegation} from './event_dispatch/event_delegation';
export {JSACTION_EVENT_CONTRACT as ɵJSACTION_EVENT_CONTRACT} from './event_delegation_utils';
export {IS_HYDRATION_DOM_REUSE_ENABLED as ɵIS_HYDRATION_DOM_REUSE_ENABLED} from './hydration/tokens';
export {
HydratedNode as ɵHydratedNode,
Expand Down
70 changes: 2 additions & 68 deletions packages/core/src/event_delegation_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@
*/

// tslint:disable:no-duplicate-imports
import {
EventContract,
EventContractContainer,
EventDispatcher,
isEarlyEventType,
getActionCache,
registerDispatcher,
} from '@angular/core/primitives/event-dispatch';
import {EventContract} from '@angular/core/primitives/event-dispatch';
import {Attribute} from '@angular/core/primitives/event-dispatch';
import {Injectable, InjectionToken, Injector, inject} from './di';
import {InjectionToken} from './di';
import {RElement} from './render3/interfaces/renderer_dom';
import {EVENT_REPLAY_ENABLED_DEFAULT, IS_EVENT_REPLAY_ENABLED} from './hydration/tokens';
import {OnDestroy} from './interface/lifecycle_hooks';

declare global {
interface Element {
Expand Down Expand Up @@ -71,60 +62,3 @@ export const JSACTION_EVENT_CONTRACT = new InjectionToken<EventContractDetails>(
factory: () => ({}),
},
);

export const GLOBAL_EVENT_DELEGATION = new InjectionToken<GlobalEventDelegation>(
ngDevMode ? 'GLOBAL_EVENT_DELEGATION' : '',
);

/**
* This class is the delegate for `EventDelegationPlugin`. It represents the
* noop version of this class, with the enabled version set when
* `provideGlobalEventDelegation` is called.
*/
@Injectable()
export class GlobalEventDelegation implements OnDestroy {
private eventContractDetails = inject(JSACTION_EVENT_CONTRACT);

ngOnDestroy() {
this.eventContractDetails.instance?.cleanUp();
}

supports(eventType: string): boolean {
return isEarlyEventType(eventType);
}

addEventListener(element: HTMLElement, eventType: string, handler: Function): Function {
// Note: contrary to the type, Window and Document can be passed in
// as well.
if (element.nodeType === Node.ELEMENT_NODE) {
this.eventContractDetails.instance!.addEvent(eventType);
getActionCache(element)[eventType] = '';
sharedStashFunction(element, eventType, handler);
} else {
element.addEventListener(eventType, handler as EventListener);
}
return () => this.removeEventListener(element, eventType, handler);
}

removeEventListener(element: HTMLElement, eventType: string, callback: Function): void {
if (element.nodeType === Node.ELEMENT_NODE) {
getActionCache(element)[eventType] = undefined;
} else {
element.removeEventListener(eventType, callback as EventListener);
}
}
}

export const initGlobalEventDelegation = (
eventContractDetails: EventContractDetails,
injector: Injector,
) => {
if (injector.get(IS_EVENT_REPLAY_ENABLED, EVENT_REPLAY_ENABLED_DEFAULT)) {
return;
}
const eventContract = (eventContractDetails.instance = new EventContract(
new EventContractContainer(document.body),
));
const dispatcher = new EventDispatcher(invokeRegisteredListeners, /** clickModSupport */ false);
registerDispatcher(eventContract, dispatcher);
};
58 changes: 0 additions & 58 deletions packages/core/src/event_dispatch/event_delegation.ts

This file was deleted.

15 changes: 2 additions & 13 deletions packages/core/src/hydration/event_replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ import {CLEANUP, LView, TView} from '../render3/interfaces/view';
import {isPlatformBrowser} from '../render3/util/misc_utils';
import {unwrapRNode} from '../render3/util/view_utils';

import {
EVENT_REPLAY_ENABLED_DEFAULT,
IS_EVENT_REPLAY_ENABLED,
IS_GLOBAL_EVENT_DELEGATION_ENABLED,
} from './tokens';
import {EVENT_REPLAY_ENABLED_DEFAULT, IS_EVENT_REPLAY_ENABLED} from './tokens';
import {
sharedStashFunction,
removeListeners,
Expand All @@ -47,18 +43,11 @@ import {performanceMarkFeature} from '../util/performance';
*/
const jsactionSet = new Set<Element>();

function isGlobalEventDelegationEnabled(injector: Injector) {
return injector.get(IS_GLOBAL_EVENT_DELEGATION_ENABLED, false);
}

/**
* Determines whether Event Replay feature should be activated on the client.
*/
function shouldEnableEventReplay(injector: Injector) {
return (
injector.get(IS_EVENT_REPLAY_ENABLED, EVENT_REPLAY_ENABLED_DEFAULT) &&
!isGlobalEventDelegationEnabled(injector)
);
return injector.get(IS_EVENT_REPLAY_ENABLED, EVENT_REPLAY_ENABLED_DEFAULT);
}

/**
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/hydration/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,3 @@ export const IS_EVENT_REPLAY_ENABLED = new InjectionToken<boolean>(
);

export const EVENT_REPLAY_ENABLED_DEFAULT = false;

/**
* Internal token that indicates whether global event delegation support is enabled.
*/
export const IS_GLOBAL_EVENT_DELEGATION_ENABLED = new InjectionToken<boolean>(
typeof ngDevMode === 'undefined' || !!ngDevMode ? 'IS_GLOBAL_EVENT_DELEGATION_ENABLED' : '',
);
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@
{
"name": "DomAdapter"
},
{
"name": "DomEventsPlugin"
},
{
"name": "DomRendererFactory2"
},
Expand Down Expand Up @@ -236,9 +233,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand All @@ -251,9 +245,6 @@
{
"name": "FALSE_BOOLEAN_VALUES"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand All @@ -272,9 +269,6 @@
{
"name": "FALSE_BOOLEAN_VALUES"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand All @@ -176,9 +173,6 @@
{
"name": "EventManagerPlugin"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down
9 changes: 0 additions & 9 deletions packages/core/test/bundling/defer/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand All @@ -209,9 +206,6 @@
{
"name": "EventManagerPlugin"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down Expand Up @@ -1436,9 +1430,6 @@
{
"name": "init_event_contract_defines"
},
{
"name": "init_event_delegation"
},
{
"name": "init_event_delegation_utils"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand Down Expand Up @@ -272,9 +269,6 @@
{
"name": "FormsExampleModule"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand All @@ -251,9 +248,6 @@
{
"name": "FormsModule"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@
{
"name": "DomAdapter"
},
{
"name": "DomEventsPlugin"
},
{
"name": "DomRendererFactory2"
},
Expand Down Expand Up @@ -170,9 +167,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand All @@ -182,9 +176,6 @@
{
"name": "EventManagerPlugin"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down
9 changes: 0 additions & 9 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@
{
"name": "DomAdapter"
},
{
"name": "DomEventsPlugin"
},
{
"name": "DomRendererFactory2"
},
Expand Down Expand Up @@ -236,9 +233,6 @@
{
"name": "ErrorHandler"
},
{
"name": "EventDelegationPlugin"
},
{
"name": "EventEmitter"
},
Expand All @@ -251,9 +245,6 @@
{
"name": "EventType2"
},
{
"name": "GLOBAL_EVENT_DELEGATION"
},
{
"name": "GenericBrowserDomAdapter"
},
Expand Down
Loading

0 comments on commit 2e7cfcb

Please sign in to comment.