MCPcopy
hub / github.com/angular/angular / pollDomTrigger

Function pollDomTrigger

packages/core/src/defer/dom_triggers.ts:145–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

143 const zone = injector.get(NgZone);
144 let poll: AfterRenderRef;
145 function pollDomTrigger() {
146 // If the initial view was destroyed, we don't need to do anything.
147 if (isDestroyed(initialLView)) {
148 poll.destroy();
149 return;
150 }
151
152 const lDetails = getLDeferBlockDetails(initialLView, tNode);
153 const renderedState = lDetails[DEFER_BLOCK_STATE];
154
155 // If the block was loaded before the trigger was resolved, we don't need to do anything.
156 if (
157 renderedState !== DeferBlockInternalState.Initial &&
158 renderedState !== DeferBlockState.Placeholder
159 ) {
160 poll.destroy();
161 return;
162 }
163
164 const triggerLView = getTriggerLView(initialLView, tNode, walkUpTimes);
165
166 // Keep polling until we resolve the trigger's LView.
167 if (!triggerLView) {
168 // Keep polling.
169 return;
170 }
171
172 poll.destroy();
173
174 // It's possible that the trigger's view was destroyed before we resolved the trigger element.
175 if (isDestroyed(triggerLView)) {
176 return;
177 }
178
179 const element = getTriggerElement(triggerLView, triggerIndex);
180 const cleanup = registerFn(
181 element,
182 () => {
183 // `pollDomTrigger` runs outside the zone (because of `afterNextRender`) and registers its
184 // listeners outside the zone, so we jump back into the zone prior to running the callback.
185 zone.run(() => {
186 if (initialLView !== triggerLView) {
187 removeLViewOnDestroy(triggerLView, cleanup);
188 }
189 callback();
190 });
191 },
192 injector,
193 options,
194 );
195
196 // The trigger and deferred block might be in different LViews.
197 // For the main LView the cleanup would happen as a part of
198 // `storeTriggerCleanupFn` logic. For trigger LView we register
199 // a cleanup function there to remove event handlers in case an
200 // LView gets destroyed before a trigger is invoked.
201 if (initialLView !== triggerLView) {
202 storeLViewOnDestroy(triggerLView, cleanup);

Callers

nothing calls this directly

Calls 10

isDestroyedFunction · 0.90
getLDeferBlockDetailsFunction · 0.90
removeLViewOnDestroyFunction · 0.90
storeLViewOnDestroyFunction · 0.90
storeTriggerCleanupFnFunction · 0.90
getTriggerLViewFunction · 0.85
getTriggerElementFunction · 0.85
callbackFunction · 0.70
destroyMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…