Skip to content

Commit

Permalink
refactor(element): use swiper state for init/destroy tracking (#7907)
Browse files Browse the repository at this point in the history
* refactor: use swiper state for init/destroy tracking

* refactor: remove optional chaining, according code base style

* refactor: update missing initialized state control
  • Loading branch information
eduardobattisti authored Mar 3, 2025
1 parent f7febe1 commit ffb3a09
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/swiper-element.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ class SwiperContainer extends ClassToExtend {
}

initialize() {
if (this.initialized) return;
this.initialized = true;
if (this.swiper && this.swiper.initialized) return;
const { params: swiperParams, passedParams } = getParams(this);
this.swiperParams = swiperParams;
this.passedParams = passedParams;
Expand Down Expand Up @@ -180,7 +179,8 @@ class SwiperContainer extends ClassToExtend {

connectedCallback() {
if (
this.initialized &&
this.swiper &&
this.swiper.initialized &&
this.nested &&
this.closest('swiper-slide') &&
this.closest('swiper-slide').swiperLoopMoveDOM
Expand All @@ -204,7 +204,6 @@ class SwiperContainer extends ClassToExtend {
if (this.swiper && this.swiper.destroy) {
this.swiper.destroy();
}
this.initialized = false;
}

updateSwiperOnPropChange(propName, propValue) {
Expand Down Expand Up @@ -238,7 +237,7 @@ class SwiperContainer extends ClassToExtend {
}

attributeChangedCallback(attr, prevValue, newValue) {
if (!this.initialized) return;
if (!(this.swiper && this.swiper.initialized)) return;
if (prevValue === 'true' && newValue === null) {
newValue = false;
}
Expand Down Expand Up @@ -269,7 +268,7 @@ paramsList.forEach((paramName) => {
set(value) {
if (!this.passedParams) this.passedParams = {};
this.passedParams[paramName] = value;
if (!this.initialized) return;
if (!(this.swiper && this.swiper.initialized)) return;
this.updateSwiperOnPropChange(paramName, value);
},
});
Expand Down

0 comments on commit ffb3a09

Please sign in to comment.