MCPcopy
hub / github.com/thebuilder/react-intersection-observer / triggerIntersection

Function triggerIntersection

src/test-utils.ts:172–230  ·  view source on GitHub ↗
(
  elements: Element[],
  trigger: boolean | number,
  observer: IntersectionObserver,
  item: Item,
)

Source from the content-addressed store, hash-verified

170}
171
172function triggerIntersection(
173 elements: Element[],
174 trigger: boolean | number,
175 observer: IntersectionObserver,
176 item: Item,
177) {
178 const entries: IntersectionObserverEntry[] = [];
179
180 const isIntersecting =
181 typeof trigger === "number"
182 ? observer.thresholds.some((threshold) => trigger >= threshold)
183 : trigger;
184
185 let ratio: number;
186
187 if (typeof trigger === "number") {
188 const intersectedThresholds = observer.thresholds.filter(
189 (threshold) => trigger >= threshold,
190 );
191 ratio =
192 intersectedThresholds.length > 0
193 ? intersectedThresholds[intersectedThresholds.length - 1]
194 : 0;
195 } else {
196 ratio = trigger ? 1 : 0;
197 }
198
199 for (const element of elements) {
200 entries.push(<IntersectionObserverEntry>{
201 boundingClientRect: element.getBoundingClientRect(),
202 intersectionRatio: ratio,
203 intersectionRect: isIntersecting
204 ? element.getBoundingClientRect()
205 : {
206 bottom: 0,
207 height: 0,
208 left: 0,
209 right: 0,
210 top: 0,
211 width: 0,
212 x: 0,
213 y: 0,
214 toJSON() {},
215 },
216 isIntersecting,
217 rootBounds:
218 observer.root instanceof Element
219 ? observer.root?.getBoundingClientRect()
220 : null,
221 target: element,
222 time: Date.now() - item.created,
223 });
224 }
225
226 // Trigger the IntersectionObserver callback with all the entries
227 const act = getActFn();
228 if (act) act(() => item.callback(entries, observer));
229 else item.callback(entries, observer);

Callers 2

mockAllIsIntersectingFunction · 0.85
mockIsIntersectingFunction · 0.85

Calls 1

getActFnFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…