Skip to content

Commit

Permalink
chore: cleanup extend method and remove bindModuleMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Aug 4, 2021
1 parent 6609958 commit 71dc7d8
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/core/breakpoints/setBreakpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function setBreakpoint() {

const isEnabled = swiper.params.enabled;

extend(swiper, {
Object.assign(swiper, {
allowTouchMove: swiper.params.allowTouchMove,
allowSlideNext: swiper.params.allowSlideNext,
allowSlidePrev: swiper.params.allowSlidePrev,
Expand Down
4 changes: 2 additions & 2 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Swiper {
swiper.$ = $;

// Extend Swiper
extend(swiper, {
Object.assign(swiper, {
enabled: swiper.params.enabled,
el,

Expand Down Expand Up @@ -516,7 +516,7 @@ class Swiper {
});
}

extend(swiper, {
Object.assign(swiper, {
$el,
el,
$wrapperEl,
Expand Down
4 changes: 2 additions & 2 deletions src/core/events/onTouchStart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getWindow, getDocument } from 'ssr-window';
import $ from '../../shared/dom.js';
import { extend, now } from '../../shared/utils.js';
import { now } from '../../shared/utils.js';

// Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
function closestElement(selector, base = this) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function onTouchStart(event) {
}
}

extend(data, {
Object.assign(data, {
isTouched: true,
isMoved: false,
allowTouchCallbacks: true,
Expand Down
4 changes: 1 addition & 3 deletions src/core/update/updateActiveIndex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { extend } from '../../shared/utils.js';

export default function updateActiveIndex(newActiveIndex) {
const swiper = this;
const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
Expand Down Expand Up @@ -54,7 +52,7 @@ export default function updateActiveIndex(newActiveIndex) {
10,
);

extend(swiper, {
Object.assign(swiper, {
snapIndex,
realIndex,
previousIndex,
Expand Down
4 changes: 1 addition & 3 deletions src/core/update/updateProgress.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { extend } from '../../shared/utils.js';

export default function updateProgress(translate) {
const swiper = this;
if (typeof translate === 'undefined') {
Expand All @@ -21,7 +19,7 @@ export default function updateProgress(translate) {
isBeginning = progress <= 0;
isEnd = progress >= 1;
}
extend(swiper, {
Object.assign(swiper, {
progress,
isBeginning,
isEnd,
Expand Down
4 changes: 1 addition & 3 deletions src/core/update/updateSize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { extend } from '../../shared/utils.js';

export default function updateSize() {
const swiper = this;
let width;
Expand Down Expand Up @@ -32,7 +30,7 @@ export default function updateSize() {
if (Number.isNaN(width)) width = 0;
if (Number.isNaN(height)) height = 0;

extend(swiper, {
Object.assign(swiper, {
width,
height,
size: swiper.isHorizontal() ? width : height,
Expand Down
4 changes: 1 addition & 3 deletions src/core/update/updateSlides.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { extend } from '../../shared/utils.js';

export default function updateSlides() {
const swiper = this;
function getDirectionLabel(property) {
Expand Down Expand Up @@ -312,7 +310,7 @@ export default function updateSlides() {
}
}

extend(swiper, {
Object.assign(swiper, {
slides,
snapGrid,
slidesGrid,
Expand Down
5 changes: 2 additions & 3 deletions src/modules/effect-cube/effect-cube.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import $ from '../../shared/dom.js';
import { extend } from '../../shared/utils.js';

export default function Cube({ swiper, extendParams, on }) {
extendParams({
Expand Down Expand Up @@ -175,8 +174,8 @@ export default function Cube({ swiper, extendParams, on }) {
centeredSlides: false,
virtualTranslate: true,
};
extend(swiper.params, overwriteParams);
extend(swiper.originalParams, overwriteParams);
Object.assign(swiper.params, overwriteParams);
Object.assign(swiper.originalParams, overwriteParams);
});
on('setTranslate', () => {
if (swiper.params.effect !== 'cube') return;
Expand Down
6 changes: 2 additions & 4 deletions src/modules/effect-fade/effect-fade.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { extend } from '../../shared/utils.js';

export default function Fade({ swiper, extendParams, on }) {
extendParams({
fadeEffect: {
Expand Down Expand Up @@ -58,8 +56,8 @@ export default function Fade({ swiper, extendParams, on }) {
spaceBetween: 0,
virtualTranslate: true,
};
extend(swiper.params, overwriteParams);
extend(swiper.originalParams, overwriteParams);
Object.assign(swiper.params, overwriteParams);
Object.assign(swiper.originalParams, overwriteParams);
});
on('setTranslate', () => {
if (swiper.params.effect !== 'fade') return;
Expand Down
6 changes: 2 additions & 4 deletions src/modules/effect-flip/effect-flip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import $ from '../../shared/dom.js';
import { extend } from '../../shared/utils.js';

export default function Flip({ swiper, extendParams, on }) {
extendParams({
Expand Down Expand Up @@ -76,7 +75,6 @@ export default function Flip({ swiper, extendParams, on }) {
slides.eq(activeIndex).transitionEnd(function onTransitionEnd() {
if (eventTriggered) return;
if (!swiper || swiper.destroyed) return;
// if (!$(this).hasClass(swiper.params.slideActiveClass)) return;
eventTriggered = true;
swiper.animating = false;
const triggerEvents = ['webkitTransitionEnd', 'transitionend'];
Expand All @@ -99,8 +97,8 @@ export default function Flip({ swiper, extendParams, on }) {
spaceBetween: 0,
virtualTranslate: true,
};
extend(swiper.params, overwriteParams);
extend(swiper.originalParams, overwriteParams);
Object.assign(swiper.params, overwriteParams);
Object.assign(swiper.originalParams, overwriteParams);
});
on('setTranslate', () => {
if (swiper.params.effect !== 'flip') return;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/navigation/navigation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import $ from '../../shared/dom.js';
import { extend, createElementIfNotDefined } from '../../shared/utils.js';
import { createElementIfNotDefined } from '../../shared/utils.js';

export default function Navigation({ swiper, extendParams, on, emit }) {
extendParams({
Expand Down Expand Up @@ -89,7 +89,7 @@ export default function Navigation({ swiper, extendParams, on, emit }) {
$prevEl.on('click', onPrevClick);
}

extend(swiper.navigation, {
Object.assign(swiper.navigation, {
$nextEl,
nextEl: $nextEl && $nextEl[0],
$prevEl,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/pagination/pagination.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import $ from '../../shared/dom.js';
import { extend, classesToSelector, createElementIfNotDefined } from '../../shared/utils.js';
import { classesToSelector, createElementIfNotDefined } from '../../shared/utils.js';

export default function Pagination({ swiper, extendParams, on, emit }) {
const pfx = 'swiper-pagination';
Expand Down Expand Up @@ -311,7 +311,7 @@ export default function Pagination({ swiper, extendParams, on, emit }) {
});
}

extend(swiper.pagination, {
Object.assign(swiper.pagination, {
$el,
el: $el[0],
});
Expand Down
4 changes: 2 additions & 2 deletions src/modules/scrollbar/scrollbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDocument } from 'ssr-window';
import $ from '../../shared/dom.js';
import { extend, nextTick, createElementIfNotDefined } from '../../shared/utils.js';
import { nextTick, createElementIfNotDefined } from '../../shared/utils.js';

export default function Scrollbar({ swiper, extendParams, on, emit }) {
const document = getDocument();
Expand Down Expand Up @@ -270,7 +270,7 @@ export default function Scrollbar({ swiper, extendParams, on, emit }) {
$el.append($dragEl);
}

extend(scrollbar, {
Object.assign(scrollbar, {
$el,
el: $el[0],
$dragEl,
Expand Down
20 changes: 10 additions & 10 deletions src/modules/thumbs/thumbs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extend, isObject } from '../../shared/utils.js';
import { isObject } from '../../shared/utils.js';
import $ from '../../shared/dom.js';

export default function Thumb({ swiper, extendParams, on }) {
Expand Down Expand Up @@ -66,22 +66,22 @@ export default function Thumb({ swiper, extendParams, on }) {
const SwiperClass = swiper.constructor;
if (thumbsParams.swiper instanceof SwiperClass) {
swiper.thumbs.swiper = thumbsParams.swiper;
extend(swiper.thumbs.swiper.originalParams, {
Object.assign(swiper.thumbs.swiper.originalParams, {
watchSlidesProgress: true,
slideToClickedSlide: false,
});
extend(swiper.thumbs.swiper.params, {
Object.assign(swiper.thumbs.swiper.params, {
watchSlidesProgress: true,
slideToClickedSlide: false,
});
} else if (isObject(thumbsParams.swiper)) {
swiper.thumbs.swiper = new SwiperClass(
extend({}, thumbsParams.swiper, {
watchSlidesVisibility: true,
watchSlidesProgress: true,
slideToClickedSlide: false,
}),
);
const thumbsSwiperParams = Object.assign({}, thumbsParams.swiper);
Object.assign(thumbsSwiperParams, {
watchSlidesVisibility: true,
watchSlidesProgress: true,
slideToClickedSlide: false,
});
swiper.thumbs.swiper = new SwiperClass(thumbsSwiperParams);
swiperCreated = true;
}
swiper.thumbs.swiper.$el.addClass(swiper.params.thumbs.thumbsContainerClass);
Expand Down
14 changes: 0 additions & 14 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,6 @@ function extend(...args) {
return to;
}

function bindModuleMethods(instance, obj) {
Object.keys(obj).forEach((key) => {
if (isObject(obj[key])) {
Object.keys(obj[key]).forEach((subKey) => {
if (typeof obj[key][subKey] === 'function') {
obj[key][subKey] = obj[key][subKey].bind(instance);
}
});
}
instance[key] = obj[key];
});
}

function classesToSelector(classes = '') {
return `.${classes
.trim()
Expand Down Expand Up @@ -175,7 +162,6 @@ export {
getTranslate,
isObject,
extend,
bindModuleMethods,
getComputedStyle,
classesToSelector,
createElementIfNotDefined,
Expand Down

0 comments on commit 71dc7d8

Please sign in to comment.