Skip to content

Commit

Permalink
feat(ES6 classes): adds the ES6 class syntax and functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunkathuria authored and arschmitz committed Sep 30, 2016
1 parent a6a59b3 commit ed3b3ab
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 366 deletions.
1 change: 1 addition & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
],
"disallowConstOutsideModuleScope": false,
"requireArrowFunctions": true,
"disallowEmptyBlocks": false
}
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"unused": true,
"-W116": true,
"-W080": true,
"-W038": true
"-W038": true,
"proto": true
}
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: node_js
node_js:
- "0.10"
- "0.12"

sudo: false

before_script:
- npm install -g grunt-cli

script:
- grunt test-travis
- grunt test-travis
26 changes: 13 additions & 13 deletions src/hammer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ifUndefined from './utils/if-undefined';
import { TOUCH_ACTION_COMPUTE } from './touchactionjs/touchaction-Consts';
import { DIRECTION_HORIZONTAL } from './inputjs/input-consts';
import { RotateRecognizer } from './recognizers/rotate';
import { PinchRecognizer } from './recognizers/pinch';
import { SwipeRecognizer } from './recognizers/swipe';
import { PanRecognizer } from './recognizers/pan';
import { TapRecognizer } from './recognizers/tap';
import { PressRecognizer } from './recognizers/press';
import { Manager } from './manager';
import RotateRecognizer from './recognizers/rotate';
import PinchRecognizer from './recognizers/pinch';
import SwipeRecognizer from './recognizers/swipe';
import PanRecognizer from './recognizers/pan';
import TapRecognizer from './recognizers/tap';
import PressRecognizer from './recognizers/press';
import Manager from './manager';

/**
* @private
Expand All @@ -16,10 +16,12 @@ import { Manager } from './manager';
* @param {Object} [options]
* @constructor
*/
function Hammer(element, options) {
options = options || {};
options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
return new Manager(element, options);
export default class Hammer {
constructor(element, options) {
options = options || {};
options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
return new Manager(element, options);
}
}

/**
Expand Down Expand Up @@ -153,5 +155,3 @@ Hammer.defaults = {
tapHighlightColor: 'rgba(0,0,0,0)'
}
};

export { Hammer };
21 changes: 9 additions & 12 deletions src/input/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
INPUT_END,
INPUT_TYPE_MOUSE
} from '../inputjs/input-consts';
import { Input } from '../inputjs/input-constructor';
import inherit from '../utils/inherit';
import Input from '../inputjs/input-constructor';

const MOUSE_INPUT_MAP = {
mousedown: INPUT_START,
Expand All @@ -22,16 +21,16 @@ const MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
* @constructor
* @extends Input
*/
function MouseInput() {
this.evEl = MOUSE_ELEMENT_EVENTS;
this.evWin = MOUSE_WINDOW_EVENTS;
export default class MouseInput extends Input {
constructor() {
super(...arguments);

this.pressed = false; // mousedown state
this.evEl = MOUSE_ELEMENT_EVENTS;
this.evWin = MOUSE_WINDOW_EVENTS;

Input.apply(this, arguments);
}
this.pressed = false; // mousedown state
}

inherit(MouseInput, Input, {
/**
* @private
* handle mouse events
Expand Down Expand Up @@ -65,6 +64,4 @@ inherit(MouseInput, Input, {
srcEvent: ev
});
}
});

export { MouseInput };
}
22 changes: 9 additions & 13 deletions src/input/pointerevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
INPUT_TYPE_PEN,
INPUT_TYPE_KINECT
} from '../inputjs/input-consts';
import { Input } from '../inputjs/input-constructor';
import inherit from '../utils/inherit';
import Input from '../inputjs/input-constructor';
import inArray from '../utils/in-array';

const POINTER_INPUT_MAP = {
Expand Down Expand Up @@ -43,16 +42,15 @@ if (window.MSPointerEvent && !window.PointerEvent) {
* @constructor
* @extends Input
*/
function PointerEventInput() {
this.evEl = POINTER_ELEMENT_EVENTS;
this.evWin = POINTER_WINDOW_EVENTS;
export default class PointerEventInput extends Input {
constructor() {
super(...arguments);
this.evEl = POINTER_ELEMENT_EVENTS;
this.evWin = POINTER_WINDOW_EVENTS;

Input.apply(this, arguments);

this.store = (this.manager.session.pointerEvents = []);
}
this.store = (this.manager.session.pointerEvents = []);
}

inherit(PointerEventInput, Input, {
/**
* @private
* handle mouse events
Expand Down Expand Up @@ -101,6 +99,4 @@ inherit(PointerEventInput, Input, {
store.splice(storeIndex, 1);
}
}
});

export { PointerEventInput };
}
22 changes: 10 additions & 12 deletions src/input/singletouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
INPUT_CANCEL,
INPUT_TYPE_TOUCH
} from '../inputjs/input-consts';
import { Input } from '../inputjs/input-constructor';
import inherit from '../utils/inherit';
import Input from '../inputjs/input-constructor';
import toArray from '../utils/to-array';
import uniqueArray from '../utils/unique-array';

Expand All @@ -26,15 +25,16 @@ const SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
* @constructor
* @extends Input
*/
function SingleTouchInput() {
this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
this.started = false;
export default class SingleTouchInput extends Input {
constructor() {
super(...arguments);
this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
this.started = false;

Input.apply(this, arguments);
}
Input.apply(this, arguments);
}

inherit(SingleTouchInput, Input, {
handler(ev) {
let type = SINGLE_TOUCH_INPUT_MAP[ev.type];

Expand All @@ -61,7 +61,7 @@ inherit(SingleTouchInput, Input, {
srcEvent: ev
});
}
});
}

/**
* @private
Expand All @@ -80,5 +80,3 @@ function normalizeSingleTouches(ev, type) {

return [all, changed];
}

export { SingleTouchInput };
22 changes: 11 additions & 11 deletions src/input/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
INPUT_CANCEL,
INPUT_TYPE_TOUCH
} from '../inputjs/input-consts';
import { Input } from '../inputjs/input-constructor';
import inherit from '../utils/inherit';
import Input from '../inputjs/input-constructor';
import toArray from '../utils/to-array';
import hasParent from '../utils/has-parent';
import uniqueArray from '../utils/unique-array';
Expand All @@ -26,14 +25,17 @@ const TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
* @constructor
* @extends Input
*/
function TouchInput() {
this.evTarget = TOUCH_TARGET_EVENTS;
this.targetIds = {};
export default class TouchInput extends Input {

Input.apply(this, arguments);
}
constructor() {
TouchInput.prototype.evTarget = TOUCH_TARGET_EVENTS;
TouchInput.prototype.targetIds = {};
super(...arguments);

this.evTarget = TOUCH_TARGET_EVENTS;
this.targetIds = {};
}

inherit(TouchInput, Input, {
handler(ev) {
let type = TOUCH_INPUT_MAP[ev.type];
let touches = getTouches.call(this, ev, type);
Expand All @@ -48,7 +50,7 @@ inherit(TouchInput, Input, {
srcEvent: ev
});
}
});
}

/**
* @private
Expand Down Expand Up @@ -111,5 +113,3 @@ function getTouches(ev, type) {
changedTargetTouches
];
}

export { TouchInput };
31 changes: 14 additions & 17 deletions src/input/touchmouse.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Input } from '../inputjs/input-constructor';
import inherit from '../utils/inherit';
import Input from '../inputjs/input-constructor';
import bindFn from '../utils/bind-fn';
import { TouchInput } from './touch';
import { MouseInput } from './mouse';
import TouchInput from './touch';
import MouseInput from './mouse';
import {
INPUT_START,
INPUT_END,
Expand All @@ -25,18 +24,18 @@ import {
const DEDUP_TIMEOUT = 2500;
const DEDUP_DISTANCE = 25;

function TouchMouseInput() {
Input.apply(this, arguments);
export default class TouchMouseInput extends Input {
constructor() {
super(...arguments);

let handler = bindFn(this.handler, this);
this.touch = new TouchInput(this.manager, handler);
this.mouse = new MouseInput(this.manager, handler);
let handler = bindFn(this.handler, this);
this.touch = new TouchInput(this.manager, handler);
this.mouse = new MouseInput(this.manager, handler);

this.primaryTouch = null;
this.lastTouches = [];
}
this.primaryTouch = null;
this.lastTouches = [];
}

inherit(TouchMouseInput, Input, {
/**
* @private
* handle mouse and touch events
Expand All @@ -60,7 +59,7 @@ inherit(TouchMouseInput, Input, {
}

this.callback(manager, inputEvent, inputData);
},
}

/**
* @private
Expand All @@ -70,7 +69,7 @@ inherit(TouchMouseInput, Input, {
this.touch.destroy();
this.mouse.destroy();
}
});
}

function recordTouches(eventType, eventData) {
if (eventType & INPUT_START) {
Expand Down Expand Up @@ -110,5 +109,3 @@ function isSyntheticEvent(eventData) {
}
return false;
}

export { TouchMouseInput };
8 changes: 4 additions & 4 deletions src/inputjs/create-input-instance.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SUPPORT_POINTER_EVENTS,SUPPORT_ONLY_TOUCH,SUPPORT_TOUCH } from './input-consts';
import inputHandler from './input-handler';
import { PointerEventInput } from '../input/pointerevent';
import { TouchInput } from '../input/touch';
import { MouseInput } from '../input/mouse';
import { TouchMouseInput } from '../input/touchmouse';
import PointerEventInput from '../input/pointerevent';
import TouchInput from '../input/touch';
import MouseInput from '../input/mouse';
import TouchMouseInput from '../input/touchmouse';

/**
* @private
Expand Down
Loading

0 comments on commit ed3b3ab

Please sign in to comment.