Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix(Swiper): 'super()' must be called in derived constructor before accessing |this| or returning non-object #2105

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading