Skip to content

Commit f3d996c

Browse files
committed
refactor(intersection.service): add options interface, move to services
1 parent 24ed302 commit f3d996c

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

projects/coreui-angular/src/lib/carousel/carousel/carousel.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '@angular/core';
1313
import { Subscription } from 'rxjs';
1414

15-
import { IntersectionService } from '../intersection.service';
15+
import { IntersectionService } from '../../services/intersection.service';
1616
import { IListenersConfig, ListenersService } from '../../services/listeners.service';
1717

1818
import { CarouselState } from '../carousel-state';

projects/coreui-angular/src/lib/carousel/intersection.service.ts renamed to projects/coreui-angular/src/lib/services/intersection.service.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Injectable, OnDestroy } from '@angular/core';
22
import { BehaviorSubject } from 'rxjs';
33

4+
interface IIntersectionObserverInit {
5+
root?: Element | null;
6+
rootMargin?: string;
7+
threshold?: number | number[];
8+
}
9+
410
@Injectable()
511
export class IntersectionService implements OnDestroy {
612

@@ -12,15 +18,17 @@ export class IntersectionService implements OnDestroy {
1218
private intersectionObserver!: IntersectionObserver;
1319
private hostElement!: { nativeElement: Element; };
1420

15-
createIntersectionObserver(hostElement: { nativeElement: Element; }) {
21+
private defaultObserverOptions: IIntersectionObserverInit = {
22+
root: null,
23+
rootMargin: '0px',
24+
threshold: 0.2
25+
};
1626

17-
this.hostElement = hostElement;
27+
createIntersectionObserver(hostElement: { nativeElement: Element; }, observerOptions = this.defaultObserverOptions) {
1828

19-
const options = {
20-
root: null,
21-
rootMargin: '0px',
22-
threshold: 0.2
23-
};
29+
const options = { ...this.defaultObserverOptions, ...observerOptions }
30+
31+
this.hostElement = hostElement;
2432

2533
const handleIntersect = (entries: any[], observer: any) => {
2634
entries.forEach((entry: any) => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export { IntersectionService } from './intersection.service';
12
export { ClassToggleService } from './class-toggle.service';

0 commit comments

Comments
 (0)