Skip to content

Commit

Permalink
add some LFs and docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
zjffun committed Jul 18, 2020
1 parent c21ddf8 commit 0e15a2d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Draggable/Sensors/MouseSensor/MouseSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export default class MouseSensor extends Sensor {
*/
this.mouseDownTimeout = null;

/**
* Save pageX coordinates for delay drag
* @property {Numbre} pageX
* @private
*/
this.pageX = null;

/**
* Save pageY coordinates for delay drag
* @property {Numbre} pageY
* @private
*/
this.pageY = null;

this[onContextMenuWhileDragging] = this[onContextMenuWhileDragging].bind(this);
this[onMouseDown] = this[onMouseDown].bind(this);
this[onMouseMove] = this[onMouseMove].bind(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ describe('MouseSensor', () => {
}
expect(dragFlow).toHaveTriggeredSensorEvent('drag:start', 1);
});

it('only triggers `drag:start` sensor event once when distance is met after delay', () => {
function dragFlow() {
clickMouse(draggableElement);
Expand Down
14 changes: 14 additions & 0 deletions src/Draggable/Sensors/TouchSensor/TouchSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ export default class TouchSensor extends Sensor {
*/
this.touchMoved = false;

/**
* Save pageX coordinates for delay drag
* @property {Numbre} pageX
* @private
*/
this.pageX = null;

/**
* Save pageY coordinates for delay drag
* @property {Numbre} pageY
* @private
*/
this.pageY = null;

this[onTouchStart] = this[onTouchStart].bind(this);
this[onTouchEnd] = this[onTouchEnd].bind(this);
this[onTouchMove] = this[onTouchMove].bind(this);
Expand Down
8 changes: 8 additions & 0 deletions src/Draggable/Sensors/TouchSensor/tests/TouchSensor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ describe('TouchSensor', () => {
touchSensor.detach();
sandbox.parentNode.removeChild(sandbox);
}

describe('common', () => {
beforeEach(setup);

afterEach(teardown);

it('cancels `drag:start` event when canceling sensor event', () => {
sandbox.addEventListener('drag:start', (event) => {
event.detail.cancel();
Expand All @@ -51,6 +54,7 @@ describe('TouchSensor', () => {

expect(dragFlow).not.toHaveTriggeredSensorEvent('drag:start');
});

it('prevents context menu while dragging', () => {
touchStart(draggableElement);
let contextMenuEvent = triggerEvent(draggableElement, 'contextmenu');
Expand Down Expand Up @@ -94,12 +98,14 @@ describe('TouchSensor', () => {
expect(touchEndEvent.defaultPrevented).toBe(true);
});
});

describe('using distance', () => {
beforeEach(() => {
setup({delay: 0, distance: 1});
});

afterEach(teardown);

it('does not trigger `drag:start` before distance has been travelled', () => {
function dragFlow() {
touchStart(draggableElement);
Expand Down Expand Up @@ -153,6 +159,7 @@ describe('TouchSensor', () => {
beforeEach(() => {
setup({delay: DRAG_DELAY, distance: 0});
});

afterEach(teardown);

it('does not trigger `drag:start` before delay ends', () => {
Expand Down Expand Up @@ -210,6 +217,7 @@ describe('TouchSensor', () => {
beforeEach(() => {
setup({delay: DRAG_DELAY, distance: 1});
});

afterEach(teardown);

it('does not trigger `drag:start` before delay ends', () => {
Expand Down

0 comments on commit 0e15a2d

Please sign in to comment.