Skip to content

Commit 249de1a

Browse files
authoredNov 25, 2021
fix: undo the clear observers (#523)
1 parent 6ed16e2 commit 249de1a

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed
 

‎src/index.tsx

+1-1
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, _observerMap } from './observe';
5+
export { observe } from './observe';
66

77
export default InView;
88

‎src/observe.ts

+4-4
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+
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

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { act } from 'react-dom/test-utils';
2-
import { _observerMap } from './index';
32

43
type Item = {
54
callback: IntersectionObserverCallback;
@@ -49,7 +48,6 @@ afterEach(() => {
4948
// @ts-ignore
5049
global.IntersectionObserver.mockClear();
5150
observers.clear();
52-
_observerMap.clear();
5351
});
5452

5553
function triggerIntersection(

1 commit comments

Comments
 (1)
Please sign in to comment.