Skip to content

Commit e30c60e

Browse files
iterianiAndrewKushnir
authored andcommitted
refactor(core): Add experimental support to have one event contract when there are multiple apps on the page. (#57355)
This may be removed if this turns out not to work out so well... PR Close #57355
1 parent 8104fc2 commit e30c60e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/core/src/event_dispatch/event_delegation.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {EventContract} from '@angular/core/primitives/event-dispatch';
910
import {ENVIRONMENT_INITIALIZER, Injector} from '../di';
1011
import {inject} from '../di/injector_compatibility';
1112
import {Provider} from '../di/interface/provider';
@@ -18,10 +19,18 @@ import {
1819

1920
import {IS_GLOBAL_EVENT_DELEGATION_ENABLED} from '../hydration/tokens';
2021

22+
declare global {
23+
interface Window {
24+
__jsaction_contract: EventContract | undefined;
25+
}
26+
}
27+
2128
/**
2229
* Returns a set of providers required to setup support for event delegation.
30+
* @param multiContract - Experimental support to provide one event contract
31+
* when there are multiple binaries on the page.
2332
*/
24-
export function provideGlobalEventDelegation(): Provider[] {
33+
export function provideGlobalEventDelegation(multiContract = false): Provider[] {
2534
return [
2635
{
2736
provide: IS_GLOBAL_EVENT_DELEGATION_ENABLED,
@@ -32,7 +41,12 @@ export function provideGlobalEventDelegation(): Provider[] {
3241
useValue: () => {
3342
const injector = inject(Injector);
3443
const eventContractDetails = injector.get(JSACTION_EVENT_CONTRACT);
44+
if (multiContract && window.__jsaction_contract) {
45+
eventContractDetails.instance = window.__jsaction_contract;
46+
return;
47+
}
3548
initGlobalEventDelegation(eventContractDetails, injector);
49+
window.__jsaction_contract = eventContractDetails.instance;
3650
},
3751
multi: true,
3852
},

0 commit comments

Comments
 (0)