Skip to content

Commit

Permalink
feat(angular): better typing
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Aug 18, 2021
1 parent 6b562fa commit e132ee8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/angular/src/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ export class SwiperComponent implements OnInit {
if (swiperParams.loop) {
swiperRef.loopedSlides = this.loopedSlides;
}
if (swiperRef.virtual && swiperRef.params.virtual.enabled) {
const isVirtualEnabled =
typeof swiperRef.params.virtual !== 'boolean' && swiperRef.params.virtual.enabled;
if (swiperRef.virtual && isVirtualEnabled) {
swiperRef.virtual.slides = this.slides;
const extendWith = {
cache: false,
Expand All @@ -573,7 +575,10 @@ export class SwiperComponent implements OnInit {

if (isPlatformBrowser(this._platformId)) {
this.swiperRef = swiperRef.init(this.elementRef.nativeElement);
if (this.swiperRef.virtual && this.swiperRef.params.virtual.enabled) {
const isEnabled =
typeof this.swiperRef.params.virtual !== 'boolean' &&
this.swiperRef.params.virtual.enabled;
if (this.swiperRef.virtual && isEnabled) {
this.swiperRef.virtual.update(true);
}
this._changeDetectorRef.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/types/modules/controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ControllerMethods {
* Pass here another Swiper instance or array with Swiper instances that should be controlled
* by this Swiper
*/
control?: Swiper;
control?: Swiper | Swiper[];
}

export interface ControllerEvents {}
Expand Down
1 change: 1 addition & 0 deletions src/types/modules/virtual.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface VirtualData {
}

export interface VirtualOptions {
enabled?: boolean;
/**
* Array with slides
*
Expand Down
18 changes: 17 additions & 1 deletion src/types/swiper-class.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ interface Swiper extends SwiperClass<SwiperEvents> {
*/
params: SwiperOptions;

/**
* Object with original initialization parameters
*/
originalParams: SwiperOptions;

/**
* Dom7 element with slider container HTML element. To get vanilla HTMLElement use `swiper.el`
*/
Expand All @@ -71,6 +76,13 @@ interface Swiper extends SwiperClass<SwiperEvents> {
*/
slides: Dom7Array;

/**
* If you use `slidesPerView:'auto'` with loop mode you should tell to Swiper how many slides it should loop (duplicate) using this parameter
*
* @default null
*/
loopedSlides: number | null;

/**
* Width of container
*/
Expand Down Expand Up @@ -304,10 +316,14 @@ interface Swiper extends SwiperClass<SwiperEvents> {
*/
attachEvents(): void;

loopCreate(): void;

loopDestroy(): void;

/**
* Initialize slider
*/
init(): void;
init(el?: HTMLElement): Swiper;

/**
* Destroy slider instance and detach all events listeners
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"strict": false,
"strictPropertyInitialization": false,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
Expand All @@ -13,8 +15,8 @@
"module": "es2020",
"lib": ["es2018", "dom"],
"paths": {
"swiper": ["src", "build/swiper.esm.js"],
"swiper/*": ["src/*"]
"swiper": ["build", "build/swiper.esm.js"],
"swiper/*": ["build/*"]
}
}
}

0 comments on commit e132ee8

Please sign in to comment.