File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -45,12 +45,16 @@ export function unobserve(element) {
4545 observerInstance . unobserve ( element )
4646 }
4747
48- const itemsLeft = INSTANCE_MAP . values ( ) . some (
49- item => item . threshold === instance . threshold ,
50- )
48+ // Check if we are stilling observing any elements with the same threshold.
49+ let itemsLeft = false
50+ INSTANCE_MAP . forEach ( item => {
51+ if ( item . threshold === instance . threshold ) {
52+ itemsLeft = true
53+ }
54+ } )
5155
5256 if ( observerInstance && ! itemsLeft ) {
53- // No more elements to observe, disconnect
57+ // No more elements to observe for threshold , disconnect observer
5458 observerInstance . disconnect ( )
5559 OBSERVER_MAP . delete ( instance . threshold )
5660 }
Original file line number Diff line number Diff line change 1+ import { observe , unobserve } from '../src/intersection'
2+
3+ global . IntersectionObserver = jest . fn ( ( ) => ( {
4+ observe : jest . fn ( ) ,
5+ unobserve : jest . fn ( ) ,
6+ disconnect : jest . fn ( ) ,
7+ } ) )
8+
9+ const el = { el : 'htmlElement' }
10+
11+ it ( 'should observe' , ( ) => {
12+ const cb = jest . fn ( )
13+ observe ( el , cb )
14+ } )
15+
16+ it ( 'should unobserve' , ( ) => {
17+ observe ( el , jest . fn ( ) )
18+ unobserve ( el )
19+ } )
You can’t perform that action at this time.
0 commit comments