Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: thebuilder/react-intersection-observer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.32.4
Choose a base ref
...
head repository: thebuilder/react-intersection-observer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.32.5
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Nov 25, 2021

  1. Update test.yml

    thebuilder authored Nov 25, 2021
    1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6ed16e2 View commit details
  2. 1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    249de1a View commit details
Showing with 6 additions and 8 deletions.
  1. +1 −1 .github/workflows/test.yml
  2. +1 −1 src/index.tsx
  3. +4 −4 src/observe.ts
  4. +0 −2 src/test-utils.ts
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v1
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
import { InView } from './InView';
export { InView } from './InView';
export { useInView } from './useInView';
export { observe, _observerMap } from './observe';
export { observe } from './observe';

export default InView;

8 changes: 4 additions & 4 deletions src/observe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ObserverInstanceCallback } from './index';

export const _observerMap = new Map<
const observerMap = new Map<
string,
{
id: string;
@@ -44,7 +44,7 @@ export function optionsToId(options: IntersectionObserverInit) {
function createObserver(options: IntersectionObserverInit) {
// Create a unique ID for this observer instance, based on the root, root margin and threshold.
let id = optionsToId(options);
let instance = _observerMap.get(id);
let instance = observerMap.get(id);

if (!instance) {
// 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) {
elements,
};

_observerMap.set(id, instance);
observerMap.set(id, instance);
}

return instance;
@@ -128,7 +128,7 @@ export function observe(
if (elements.size === 0) {
// No more elements are being observer by this instance, so destroy it
observer.disconnect();
_observerMap.delete(id);
observerMap.delete(id);
}
};
}
2 changes: 0 additions & 2 deletions src/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { act } from 'react-dom/test-utils';
import { _observerMap } from './index';

type Item = {
callback: IntersectionObserverCallback;
@@ -49,7 +48,6 @@ afterEach(() => {
// @ts-ignore
global.IntersectionObserver.mockClear();
observers.clear();
_observerMap.clear();
});

function triggerIntersection(