MCPcopy
hub / github.com/ampproject/amphtml / registerContainer

Method registerContainer

src/utils/display-observer.js:178–202  ·  view source on GitHub ↗

* @param {!Element} container * @param {?Element=} opt_root

(container, opt_root)

Source from the content-addressed store, hash-verified

176 * @param {?Element=} opt_root
177 */
178 registerContainer(container, opt_root) {
179 const existing = findObserverByContainer(this.observers_, container);
180 if (existing != -1) {
181 return;
182 }
183
184 /** @type {!ObserverDef} */
185 const observer = {
186 container,
187 root: opt_root || container,
188 contains: (target) => containsNotSelf(container, target),
189 // Start with null as IntersectionObserver. Will be initialized when
190 // the container itself becomes displayed.
191 io: null,
192 };
193 const index = this.observers_.length;
194 this.observers_.push(observer);
195 this.observe(container, this.containerObserved_);
196
197 this.targetObserverCallbacks_.forEach((_, target) => {
198 // Reset observation to `null` and wait for the actual measurement.
199 const value = observer.contains(target) ? null : false;
200 this.setObservation_(target, index, value, /* callbacks */ null);
201 });
202 }
203
204 /**
205 * @param {!Element} container

Callers 1

registerContainerFunction · 0.80

Calls 7

observeMethod · 0.95
setObservation_Method · 0.95
containsNotSelfFunction · 0.90
findObserverByContainerFunction · 0.85
pushMethod · 0.45
forEachMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected