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

Function pollDomTrigger

packages/core/src/defer/dom_triggers.ts:145–207  ·  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 // The trigger index can be null if the defer block is invalid.
176 if (isDestroyed(triggerLView) || triggerIndex === null) {
177 return;
178 }
179
180 const element = getTriggerElement(triggerLView, triggerIndex);
181 const cleanup = registerFn(
182 element,
183 () => {
184 // `pollDomTrigger` runs outside the zone (because of `afterNextRender`) and registers its
185 // listeners outside the zone, so we jump back into the zone prior to running the callback.
186 zone.run(() => {
187 if (initialLView !== triggerLView) {
188 removeLViewOnDestroy(triggerLView, cleanup);
189 }
190 callback();
191 });
192 },
193 injector,
194 options,
195 );
196
197 // The trigger and deferred block might be in different LViews.
198 // For the main LView the cleanup would happen as a part of
199 // `storeTriggerCleanupFn` logic. For trigger LView we register
200 // a cleanup function there to remove event handlers in case an
201 // LView gets destroyed before a trigger is invoked.
202 if (initialLView !== triggerLView) {

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