From b8f87f6ca76f278b8c67e8107677f8c28b488d1e Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 15 Jun 2019 09:34:34 +0200 Subject: [PATCH] Clean dragger --- src/utils/Dragger.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/Dragger.js b/src/utils/Dragger.js index 7c7d25273..b01f0d801 100644 --- a/src/utils/Dragger.js +++ b/src/utils/Dragger.js @@ -1,6 +1,8 @@ import { bindAll, isFunction, result, isUndefined } from 'underscore'; import { on, off, isEscKey, getPointerEvent } from 'utils/mixins'; +const resetPos = () => ({ x: 0, y: 0 }); + export default class Dragger { /** * Init the dragger @@ -63,7 +65,7 @@ export default class Dragger { }; bindAll(this, 'drag', 'stop', 'keyHandle', 'handleScroll'); this.setOptions(opts); - this.delta = { x: 0, y: 0 }; + this.delta = resetPos(); return this; } @@ -114,10 +116,8 @@ export default class Dragger { this.guidesTarget = result(opts, 'guidesTarget') || []; isFunction(onStart) && onStart(ev, this); this.startPosition = this.getStartPosition(); - this.lastDiff = 0; - this.globDiff = 0; - this.lastScrollDiff = { x: 0, y: 0 }; - this.globScrollDiff = { x: 0, y: 0 }; + this.lastScrollDiff = resetPos(); + this.globScrollDiff = resetPos(); this.drag(ev); } @@ -139,7 +139,7 @@ export default class Dragger { x: currentPos.x - startPointer.x + glDiff.x, y: currentPos.y - startPointer.y + glDiff.y }; - this.lastScrollDiff = { x: 0, y: 0 }; + this.lastScrollDiff = resetPos(); let { lockedAxis } = this; // Lock one axis @@ -351,7 +351,7 @@ export default class Dragger { getStartPosition() { const { el, opts } = this; const getPos = opts.getPosition; - let result = { x: 0, y: 0 }; + let result = resetPos(); if (isFunction(getPos)) { result = getPos();