MCPcopy Create free account
hub / github.com/angular/angular / initEventReplay

Function initEventReplay

packages/core/src/hydration/event_replay.ts:216–250  ·  view source on GitHub ↗
(eventDelegation: EventContractDetails, injector: Injector)

Source from the content-addressed store, hash-verified

214
215/** @returns false if there was no early event data to replay (another app already used it). */
216const initEventReplay = (eventDelegation: EventContractDetails, injector: Injector): boolean => {
217 const appId = injector.get(APP_ID);
218 // This is set in packages/platform-server/src/utils.ts. Two apps can share an APP_ID
219 // (duplicate bootstrap script, embedded widget), so it may already be cleared.
220 const earlyJsactionData = window._ejsas?.[appId];
221 if (!earlyJsactionData) {
222 console.warn(
223 formatRuntimeError(
224 RuntimeErrorCode.EVENT_REPLAY_CONTRACT_ALREADY_CONSUMED,
225 ngDevMode &&
226 `Event replay was skipped for APP_ID "${appId}". Another application on this page ` +
227 `already consumed the early event contract for this APP_ID. APP_ID must be unique ` +
228 `per application when multiple Angular applications share a page.`,
229 ),
230 );
231 return false;
232 }
233 const eventContract = (eventDelegation.instance = new EventContract(
234 new EventContractContainer(earlyJsactionData.c),
235 ));
236 for (const et of earlyJsactionData.et) {
237 eventContract.addEvent(et);
238 }
239 for (const et of earlyJsactionData.etc) {
240 eventContract.addEvent(et);
241 }
242 const eventInfos = getAppScopedQueuedEventInfos(appId);
243 eventContract.replayEarlyEventInfos(eventInfos);
244 clearAppScopedEarlyEventContract(appId);
245 const dispatcher = new EventDispatcher((event) => {
246 invokeRegisteredReplayListeners(injector, event, event.currentTarget as Element);
247 });
248 registerDispatcher(eventContract, dispatcher);
249 return true;
250};
251
252/**
253 * Extracts information about all DOM events (added in a template) registered on elements in a give

Callers 1

withEventReplayFunction · 0.85

Calls 9

formatRuntimeErrorFunction · 0.90
registerDispatcherFunction · 0.90
addEventMethod · 0.80
replayEarlyEventInfosMethod · 0.80
getMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected