Skip to content

Commit ffb3a09

Browse files
refactor(element): use swiper state for init/destroy tracking (#7907)
* refactor: use swiper state for init/destroy tracking * refactor: remove optional chaining, according code base style * refactor: update missing initialized state control
1 parent f7febe1 commit ffb3a09

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/swiper-element.mjs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ class SwiperContainer extends ClassToExtend {
147147
}
148148

149149
initialize() {
150-
if (this.initialized) return;
151-
this.initialized = true;
150+
if (this.swiper && this.swiper.initialized) return;
152151
const { params: swiperParams, passedParams } = getParams(this);
153152
this.swiperParams = swiperParams;
154153
this.passedParams = passedParams;
@@ -180,7 +179,8 @@ class SwiperContainer extends ClassToExtend {
180179

181180
connectedCallback() {
182181
if (
183-
this.initialized &&
182+
this.swiper &&
183+
this.swiper.initialized &&
184184
this.nested &&
185185
this.closest('swiper-slide') &&
186186
this.closest('swiper-slide').swiperLoopMoveDOM
@@ -204,7 +204,6 @@ class SwiperContainer extends ClassToExtend {
204204
if (this.swiper && this.swiper.destroy) {
205205
this.swiper.destroy();
206206
}
207-
this.initialized = false;
208207
}
209208

210209
updateSwiperOnPropChange(propName, propValue) {
@@ -238,7 +237,7 @@ class SwiperContainer extends ClassToExtend {
238237
}
239238

240239
attributeChangedCallback(attr, prevValue, newValue) {
241-
if (!this.initialized) return;
240+
if (!(this.swiper && this.swiper.initialized)) return;
242241
if (prevValue === 'true' && newValue === null) {
243242
newValue = false;
244243
}
@@ -269,7 +268,7 @@ paramsList.forEach((paramName) => {
269268
set(value) {
270269
if (!this.passedParams) this.passedParams = {};
271270
this.passedParams[paramName] = value;
272-
if (!this.initialized) return;
271+
if (!(this.swiper && this.swiper.initialized)) return;
273272
this.updateSwiperOnPropChange(paramName, value);
274273
},
275274
});

0 commit comments

Comments
 (0)