File tree Expand file tree Collapse file tree 3 files changed +7
-16
lines changed
Expand file tree Collapse file tree 3 files changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as React from 'react';
22import { InView } from './InView' ;
33export { InView } from './InView' ;
44export { useInView } from './useInView' ;
5- export { observe } from './observe' ;
5+ export { observe , _observerMap } from './observe' ;
66
77export default InView ;
88
@@ -13,15 +13,6 @@ export type ObserverInstanceCallback = (
1313 entry : IntersectionObserverEntry ,
1414) => void ;
1515
16- export type ObserverInstance = {
17- inView : boolean ;
18- readonly callback : ObserverInstanceCallback ;
19- readonly element : Element ;
20- readonly observerId : string ;
21- readonly observer : IntersectionObserver ;
22- readonly thresholds : ReadonlyArray < number > ;
23- } ;
24-
2516interface RenderProps {
2617 inView : boolean ;
2718 entry : IntersectionObserverEntry | undefined ;
Original file line number Diff line number Diff line change 11import { ObserverInstanceCallback } from './index' ;
22
3- export const ObserverMap = new Map <
3+ export const _observerMap = new Map <
44 string ,
55 {
66 id : string ;
@@ -44,7 +44,7 @@ export function optionsToId(options: IntersectionObserverInit) {
4444function createObserver ( options : IntersectionObserverInit ) {
4545 // Create a unique ID for this observer instance, based on the root, root margin and threshold.
4646 let id = optionsToId ( options ) ;
47- let instance = ObserverMap . get ( id ) ;
47+ let instance = _observerMap . get ( id ) ;
4848
4949 if ( ! instance ) {
5050 // Create a map of elements this observer is going to observe. Each element has a list of callbacks that should be triggered, once it comes into view.
@@ -85,7 +85,7 @@ function createObserver(options: IntersectionObserverInit) {
8585 elements,
8686 } ;
8787
88- ObserverMap . set ( id , instance ) ;
88+ _observerMap . set ( id , instance ) ;
8989 }
9090
9191 return instance ;
@@ -128,7 +128,7 @@ export function observe(
128128 if ( elements . size === 0 ) {
129129 // No more elements are being observer by this instance, so destroy it
130130 observer . disconnect ( ) ;
131- ObserverMap . delete ( id ) ;
131+ _observerMap . delete ( id ) ;
132132 }
133133 } ;
134134}
Original file line number Diff line number Diff line change 11import { act } from 'react-dom/test-utils' ;
2- import { ObserverMap } from './observe ' ;
2+ import { _observerMap } from './index ' ;
33
44type Item = {
55 callback : IntersectionObserverCallback ;
@@ -49,7 +49,7 @@ afterEach(() => {
4949 // @ts -ignore
5050 global . IntersectionObserver . mockClear ( ) ;
5151 observers . clear ( ) ;
52- ObserverMap . clear ( ) ;
52+ _observerMap . clear ( ) ;
5353} ) ;
5454
5555function triggerIntersection (
You can’t perform that action at this time.
0 commit comments