Skip to content

Commit d4ecf3a

Browse files
authored
fix: correct import path for observermap (#522)
1 parent a6d11be commit d4ecf3a

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

src/index.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { InView } from './InView';
33
export { InView } from './InView';
44
export { useInView } from './useInView';
5-
export { observe } from './observe';
5+
export { observe, _observerMap } from './observe';
66

77
export 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-
2516
interface RenderProps {
2617
inView: boolean;
2718
entry: IntersectionObserverEntry | undefined;

src/observe.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { 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) {
4444
function 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
}

src/test-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { act } from 'react-dom/test-utils';
2-
import { ObserverMap } from './observe';
2+
import { _observerMap } from './index';
33

44
type 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

5555
function triggerIntersection(

0 commit comments

Comments
 (0)