Skip to content

Commit

Permalink
šŸ› fix(Swiper): 'super()' must be called in derived constructor beforeā€¦
Browse files Browse the repository at this point in the history
ā€¦ accessing |this| or returning non-object (#2105)
  • Loading branch information
capdiem authored Aug 16, 2024
1 parent a053c7a commit b059511
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
13 changes: 0 additions & 13 deletions src/Masa.Blazor.JS/src/proxies/baseProxy.ts

This file was deleted.

26 changes: 15 additions & 11 deletions src/Masa.Blazor.JS/src/proxies/swiper/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import SwiperClass from "swiper";
import { SwiperOptions } from "swiper/types/swiper-options";

import { BaseProxy } from "../baseProxy";

declare const Swiper: SwiperClass;

class SwiperProxy extends BaseProxy<SwiperClass> {
class SwiperProxy {
handle: DotNet.DotNetObject;
swiper: SwiperClass;

constructor(
el: HTMLElement,
Expand Down Expand Up @@ -35,34 +34,39 @@ class SwiperProxy extends BaseProxy<SwiperClass> {
}

const swiper = new (Swiper as any)(el, swiperOptions);
super(swiper);

this.swiper = swiper;
this.handle = handle;
this.target.on("realIndexChange", (e) => this.onRealIndexChange(e, this));
this.swiper.on("realIndexChange", (e) => this.onRealIndexChange(e, this));

el._swiper = {
instance: this.target,
instance: this.swiper,
handle: handle,
};
}

slideTo(index: number, speed?: number, runCallbacks?: boolean) {
this.target.slideToLoop(index, speed, runCallbacks);
this.swiper.slideToLoop(index, speed, runCallbacks);
}

slideNext(speed?: number) {
this.target.slideNext(speed);
this.swiper.slideNext(speed);
}

slidePrev(speed?: number) {
this.target.slidePrev(speed);
this.swiper.slidePrev(speed);
}

dispose() {
this.target && this.target.destroy(true);
this.swiper && this.swiper.destroy(true);
this.handle.dispose();
}

invokeVoid(prop: string, ...args: any[]) {
if (this.swiper[prop] && typeof this.swiper[prop] === "function") {
this.swiper[prop](...args);
}
}

async onRealIndexChange(e: SwiperClass, that: SwiperProxy) {
if (that.handle) {
await that.handle.invokeMethodAsync("OnIndexChanged", e.realIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/Masa.Blazor/wwwroot/js/proxies/swiper-proxy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b059511

Please sign in to comment.