Skip to content

Commit

Permalink
fix: 馃悰 several intersection events on the same tick
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharkazaz committed Nov 21, 2020
1 parent 6f476b2 commit 6eab305
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion projects/ngneat/helipopper/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export function inView(
return;
}

const observer = new IntersectionObserver(([entry]) => {
const observer = new IntersectionObserver(entries => {
// Several changes may occur in the same tick, we want to check the latest entry state.
const entry = last(entries);
if (entry.isIntersecting) {
subscriber.next();
subscriber.complete();
Expand Down Expand Up @@ -192,3 +194,7 @@ export class TemplatePortal {
this.viewRef.destroy();
}
}

function last<T>(arr: T[]): T {
return arr[arr.length - 1];
}

0 comments on commit 6eab305

Please sign in to comment.