Skip to content

Commit

Permalink
refactor(everything) Rename stuff for better gzip compression
Browse files Browse the repository at this point in the history
  • Loading branch information
berndartmueller committed Aug 16, 2020
1 parent b8f5d53 commit 6a99ccd
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 94 deletions.
18 changes: 9 additions & 9 deletions src/components/clone/clone.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ export default class CloneComponent implements BaseComponent {
private _clonesBefore: SlideComponent[] = [];
private _clonesAfter: SlideComponent[] = [];

private swiperInstance: Virchual;
private instance: Virchual;
private virtual: VirtualComponent;
private track: TrackComponent;

constructor(private options: VirchualOptions) {}

mount(instance: Virchual, components: VirchualComponents) {
this.swiperInstance = instance;
this.instance = instance;
this.virtual = components.Virtual as VirtualComponent;
this.track = components.Track as TrackComponent;

if (this.swiperInstance.is(LOOP)) {
if (this.instance.is(LOOP)) {
this.generateClones();

this.swiperInstance.on('refresh', () => {
this.instance.on('refresh', () => {
this.destroy();
this.generateClones();
});

this.swiperInstance.on('move', () => {
this.instance.on('move', () => {
this.generateClones();
});
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export default class CloneComponent implements BaseComponent {
const slides = this.virtual.getSlides();
const firstSlide = slides[0];

const currentIndex = this.swiperInstance.index;
const currentIndex = this.instance.index;
const virtualSlidesLength = this.virtual.getSlides(false).length;

if (currentIndex > 0 && currentIndex >= virtualSlidesLength - 1 && this.lengthAfter === 0) {
Expand All @@ -109,7 +109,7 @@ export default class CloneComponent implements BaseComponent {

this._clonesAfter.push(slideClone);

this.swiperInstance.emit('cloned');
this.instance.emit('cloned');
});
}

Expand All @@ -124,7 +124,7 @@ export default class CloneComponent implements BaseComponent {

this._clonesBefore.push(slideClone);

this.swiperInstance.emit('cloned');
this.instance.emit('cloned');
});
}
}
Expand All @@ -143,7 +143,7 @@ export default class CloneComponent implements BaseComponent {
private cloneDeeply(element: HTMLElement): HTMLElement {
const clone = element.cloneNode(true) as HTMLElement;

addClass(clone, this.swiperInstance.classes.clone);
addClass(clone, this.instance.classes.clone);

// ID should not be duplicated.
removeAttribute(clone, 'id');
Expand Down
28 changes: 14 additions & 14 deletions src/components/controller/controller.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export default class ControllerComponent implements BaseComponent {
*/
private isLoop: boolean = true;

private swiperInstance: Virchual;
private instance: Virchual;
private track: TrackComponent;

constructor(private options: VirchualOptions) {}

mount(instance: Virchual, components: VirchualComponents) {
this.swiperInstance = instance;
this.instance = instance;
this.track = components.Track as TrackComponent;

this.bind();
Expand Down Expand Up @@ -47,7 +47,7 @@ export default class ControllerComponent implements BaseComponent {
* @return A parsed target.
*/
parse(control: string | number): number {
let index = this.swiperInstance.index;
let index = this.instance.index;

const matches = String(control).match(/([+\-<>])(\d+)?/);
const indicator = matches ? matches[1] : '';
Expand Down Expand Up @@ -89,7 +89,7 @@ export default class ControllerComponent implements BaseComponent {
return page;
}

const length = this.swiperInstance.length;
const length = this.instance.length;
const perPage = this.options.perPage;

let index = page * perPage;
Expand All @@ -115,7 +115,7 @@ export default class ControllerComponent implements BaseComponent {
return index;
}

const length = this.swiperInstance.length;
const length = this.instance.length;
const perPage = this.options.perPage;

// Make the last "perPage" number of slides belong to the last page.
Expand Down Expand Up @@ -186,7 +186,7 @@ export default class ControllerComponent implements BaseComponent {
* @return Max page number.
*/
get pageLength(): number {
const length = this.swiperInstance.length;
const length = this.instance.length;
return this.hasFocus() ? length : Math.ceil(length / this.options.perPage);
}

Expand All @@ -196,7 +196,7 @@ export default class ControllerComponent implements BaseComponent {
* @return Edge index.
*/
get edgeIndex(): number {
const length = this.swiperInstance.length;
const length = this.instance.length;

if (!length) {
return 0;
Expand All @@ -215,7 +215,7 @@ export default class ControllerComponent implements BaseComponent {
* @return The index of the previous slide if available. -1 otherwise.
*/
get prevIndex(): number {
let prev = this.swiperInstance.index - 1;
let prev = this.instance.index - 1;

if (this.isLoop || this.options.rewind) {
prev = this.rewind(prev);
Expand All @@ -230,27 +230,27 @@ export default class ControllerComponent implements BaseComponent {
* @return The index of the next slide if available. -1 otherwise.
*/
get nextIndex(): number {
let next = this.swiperInstance.index + 1;
let next = this.instance.index + 1;

if (this.isLoop || this.options.rewind) {
next = this.rewind(next);
}

return (this.swiperInstance.index < next && next <= this.edgeIndex) || next === 0 ? next : -1;
return (this.instance.index < next && next <= this.edgeIndex) || next === 0 ? next : -1;
}

/**
* Listen some events.
*/
private bind() {
this.swiperInstance.on('move', newIndex => {
this.swiperInstance.index = newIndex;
this.instance.on('move', newIndex => {
this.instance.index = newIndex;
});

this.swiperInstance.on('updated refresh', newOptions => {
this.instance.on('updated refresh', newOptions => {
this.options = newOptions || this.options;

this.swiperInstance.index = between(this.swiperInstance.index, 0, this.edgeIndex);
this.instance.index = between(this.instance.index, 0, this.edgeIndex);
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/components/drag/drag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ export default class DragComponent implements BaseComponent {
private track: TrackComponent;
private layout: BaseLayout;
private controller: ControllerComponent;
private swiperInstance: Virchual;
private instance: Virchual;

constructor(private options: VirchualOptions) {}

mount(instance: Virchual, components: VirchualComponents) {
this.swiperInstance = instance;
this.instance = instance;
this.track = components.Track as TrackComponent;
this.layout = components.Layout as BaseLayout;
this.controller = components.Controller as ControllerComponent;

this.swiperInstance.on('touchstart mousedown', this.onStart.bind(this), this.track.list);
this.swiperInstance.on('touchmove mousemove', this.onMove.bind(this), this.track.list, { passive: false });
this.swiperInstance.on('touchend touchcancel mouseleave mouseup dragend', this.onEnd.bind(this), this.track.list);
this.instance.on('touchstart mousedown', this.onStart.bind(this), this.track.list);
this.instance.on('touchmove mousemove', this.onMove.bind(this), this.track.list, { passive: false });
this.instance.on('touchend touchcancel mouseleave mouseup dragend', this.onEnd.bind(this), this.track.list);
}

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ export default class DragComponent implements BaseComponent {
this.track.translate(this.resist(position));
} else {
if (this.shouldMove(this.currentInfo)) {
this.swiperInstance.emit('drag', this.startInfo);
this.instance.emit('drag', this.startInfo);

this.isDragging = true;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ export default class DragComponent implements BaseComponent {
this.startInfo = null;

if (this.isDragging) {
this.swiperInstance.emit('dragged', this.currentInfo);
this.instance.emit('dragged', this.currentInfo);

this.go(this.currentInfo);

Expand Down Expand Up @@ -172,7 +172,7 @@ export default class DragComponent implements BaseComponent {
let index = this.track.direction.toIndex(destination);

// Do not allow the track to go to a previous position.
if (index === this.swiperInstance.index) {
if (index === this.instance.index) {
index += sign * this.track.direction.sign;
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/layout/directions/horizontal-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export class HorizontalLayout extends BaseLayout {
private _gap: number;

initLayout() {
this._gap = toPixel(this.swiperInstance.root, this.options.gap);
this._gap = toPixel(this.instance.root, this.options.gap);

const padding = this.options.padding || { left: 0, right: 0 };
const { left, right } = padding;

this.padding = {
left: toPixel(this.swiperInstance.root, left),
right: toPixel(this.swiperInstance.root, right),
left: toPixel(this.instance.root, left),
right: toPixel(this.instance.root, right),
};

applyStyle(this.track.list, {
Expand Down Expand Up @@ -71,7 +71,7 @@ export class HorizontalLayout extends BaseLayout {
get slideHeight() {
const height = this.options.height || this.options.fixedHeight || this.width * this.options.heightRatio;

return toPixel(this.swiperInstance.root, height);
return toPixel(this.instance.root, height);
}

/**
Expand All @@ -90,7 +90,7 @@ export class HorizontalLayout extends BaseLayout {

const width: string | number = this.options.fixedWidth || (this.width + this.gap) / this.options.perPage - this.gap;

return toPixel(this.swiperInstance.root, width);
return toPixel(this.instance.root, width);
}

get height(): number {
Expand Down
16 changes: 8 additions & 8 deletions src/components/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import VirtualComponent from '../virtual/virtual.component';
const THROTTLE = 100;

export abstract class BaseLayout implements BaseComponent {
protected swiperInstance: Virchual;
protected instance: Virchual;
protected track: TrackComponent;
protected virtual: VirtualComponent;

Expand All @@ -30,7 +30,7 @@ export abstract class BaseLayout implements BaseComponent {
abstract get width(): number;

mount(instance: Virchual, components: VirchualComponents) {
this.swiperInstance = instance;
this.instance = instance;
this.virtual = components.Virtual as VirtualComponent;
this.track = components.Track as TrackComponent;

Expand All @@ -41,7 +41,7 @@ export abstract class BaseLayout implements BaseComponent {
private init() {
this.initLayout();

applyStyle(this.swiperInstance.root, { maxWidth: unit(this.options.width) });
applyStyle(this.instance.root, { maxWidth: unit(this.options.width) });

this.virtual.each(slide => {
slide.slide.style[this.margin] = unit(this.gap);
Expand All @@ -55,16 +55,16 @@ export abstract class BaseLayout implements BaseComponent {
* Initialize when the component is mounted or options are updated.
*/
private bind() {
this.swiperInstance.on(
this.instance.on(
'resize load',
throttle(() => {
this.swiperInstance.emit('resize');
this.instance.emit('resize');
}, THROTTLE),
window,
);
this.swiperInstance.on('resize', this.onResize.bind(this));
this.swiperInstance.on('updated refresh cloned', this.init.bind(this));
this.swiperInstance.on('add', this.onResizeSlide.bind(this));
this.instance.on('resize', this.onResize.bind(this));
this.instance.on('updated refresh cloned', this.init.bind(this));
this.instance.on('add', this.onResizeSlide.bind(this));
}

/**
Expand Down
Loading

0 comments on commit 6a99ccd

Please sign in to comment.