Skip to content

Commit

Permalink
feat(stream): check if intersection observer API is supported if View…
Browse files Browse the repository at this point in the history
…PortStrategy is active; fallback do DefaultStrategy
  • Loading branch information
michaelbe812 committed Apr 12, 2023
1 parent 7b2197e commit 00296bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libs/stream/src/lib/stream.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {RenderContext} from './types/render-context';
import {StreamDirectiveContext} from './types/stream-directive-context';
import {setupOperator$} from './util/setup-operator';
import {createIntersectionObserver} from "@angular-kit/rx/platform";
import {supportsIntersectionObserver} from "./util/supports-intersection-observer";

@Directive({
selector: '[stream]',
Expand Down Expand Up @@ -162,6 +163,9 @@ export class StreamDirective<T> implements OnInit, OnDestroy {
mergeAll(),
switchMap((strategy) => {
if (isViewportRenderStrategy(strategy)){
if (!supportsIntersectionObserver()){
return of(null);
}
return createIntersectionObserver(this.viewContainerRef.element.nativeElement.parentElement, {
threshold: strategy.threshold,
rootMargin: strategy.rootMargin,
Expand Down
7 changes: 7 additions & 0 deletions libs/stream/src/lib/util/supports-intersection-observer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @internal
* Checks if the browser supports IntersectionObserver.
*/
export function supportsIntersectionObserver() {
return typeof window.IntersectionObserver !== 'undefined';
}

0 comments on commit 00296bb

Please sign in to comment.