From 48a8d9bc73cb15a89fba6e0d38afa52572b2f880 Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Fri, 15 Jul 2016 20:37:59 +0530 Subject: [PATCH] chore: moves 'defaults' out of the constructor --- src/recognizerjs/recognizer-constructor.js | 4 ++-- src/recognizers/attribute.js | 17 +++++++++-------- src/recognizers/pan.js | 13 +++++++------ src/recognizers/pinch.js | 11 ++++++----- src/recognizers/press.js | 13 +++++++------ src/recognizers/rotate.js | 11 ++++++----- src/recognizers/swipe.js | 17 +++++++++-------- src/recognizers/tap.js | 19 ++++++++++--------- 8 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/recognizerjs/recognizer-constructor.js b/src/recognizerjs/recognizer-constructor.js index a6f7b7d41..e128f2b07 100644 --- a/src/recognizerjs/recognizer-constructor.js +++ b/src/recognizerjs/recognizer-constructor.js @@ -54,8 +54,6 @@ import stateStr from './state-str'; */ export default class Recognizer { constructor(options) { - Recognizer.prototype.defaults = {}; - this.options = assign({}, this.defaults, options || {}); this.id = uniqueId(); @@ -300,3 +298,5 @@ export default class Recognizer { */ reset() { } } + +Recognizer.prototype.defaults = {}; diff --git a/src/recognizers/attribute.js b/src/recognizers/attribute.js index 4cfaf7bfb..19d069a12 100644 --- a/src/recognizers/attribute.js +++ b/src/recognizers/attribute.js @@ -19,14 +19,6 @@ import { */ export default class AttrRecognizer extends Recognizer { constructor() { - AttrRecognizer.prototype.defaults = { - /** - * @private - * @type {Number} - * @default 1 - */ - pointers: 1 - }; super(...arguments); } @@ -70,3 +62,12 @@ export default class AttrRecognizer extends Recognizer { return STATE_FAILED; } } + +AttrRecognizer.prototype.defaults = { + /** + * @private + * @type {Number} + * @default 1 + */ + pointers: 1 +}; diff --git a/src/recognizers/pan.js b/src/recognizers/pan.js index 35e448dce..fb0413d97 100644 --- a/src/recognizers/pan.js +++ b/src/recognizers/pan.js @@ -22,12 +22,6 @@ import directionStr from '../recognizerjs/direction-str'; */ export default class PanRecognizer extends AttrRecognizer { constructor() { - PanRecognizer.prototype.defaults = { - event: 'pan', - threshold: 10, - pointers: 1, - direction: DIRECTION_ALL - }; super(...arguments); this.pX = null; this.pY = null; @@ -87,3 +81,10 @@ export default class PanRecognizer extends AttrRecognizer { super.emit(input); } } + +PanRecognizer.prototype.defaults = { + event: 'pan', + threshold: 10, + pointers: 1, + direction: DIRECTION_ALL +}; diff --git a/src/recognizers/pinch.js b/src/recognizers/pinch.js index e0ae931a3..a9fadc161 100644 --- a/src/recognizers/pinch.js +++ b/src/recognizers/pinch.js @@ -11,11 +11,6 @@ import { STATE_BEGAN } from '../recognizerjs/recognizer-consts'; */ export default class PinchRecognizer extends AttrRecognizer { constructor() { - PinchRecognizer.prototype.defaults = { - event: 'pinch', - threshold: 0, - pointers: 2 - }; super(...arguments); } @@ -36,3 +31,9 @@ export default class PinchRecognizer extends AttrRecognizer { super.emit(input); } } + +PinchRecognizer.prototype.defaults = { + event: 'pinch', + threshold: 0, + pointers: 2 +}; diff --git a/src/recognizers/press.js b/src/recognizers/press.js index 46dc84517..bfa454fdd 100644 --- a/src/recognizers/press.js +++ b/src/recognizers/press.js @@ -21,12 +21,6 @@ import { */ export default class PressRecognizer extends Recognizer { constructor() { - PressRecognizer.prototype.defaults = { - event: 'press', - pointers: 1, - time: 251, // minimal time of the pointer to be pressed - threshold: 9 // a minimal movement is ok, but keep it low - }; super(...arguments); this._timer = null; this._input = null; @@ -77,3 +71,10 @@ export default class PressRecognizer extends Recognizer { } } } + +PressRecognizer.prototype.defaults = { + event: 'press', + pointers: 1, + time: 251, // minimal time of the pointer to be pressed + threshold: 9 // a minimal movement is ok, but keep it low +}; diff --git a/src/recognizers/rotate.js b/src/recognizers/rotate.js index 98afd4a71..1e3684ff4 100644 --- a/src/recognizers/rotate.js +++ b/src/recognizers/rotate.js @@ -11,11 +11,6 @@ import { STATE_BEGAN } from '../recognizerjs/recognizer-consts'; */ export default class RotateRecognizer extends AttrRecognizer { constructor() { - RotateRecognizer.prototype.defaults = { - event: 'rotate', - threshold: 0, - pointers: 2 - }; super(...arguments); } @@ -28,3 +23,9 @@ export default class RotateRecognizer extends AttrRecognizer { (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN); } } + +RotateRecognizer.prototype.defaults = { + event: 'rotate', + threshold: 0, + pointers: 2 +}; diff --git a/src/recognizers/swipe.js b/src/recognizers/swipe.js index afc3203aa..d53a26c96 100644 --- a/src/recognizers/swipe.js +++ b/src/recognizers/swipe.js @@ -12,15 +12,8 @@ import directionStr from '../recognizerjs/direction-str'; * @constructor * @extends AttrRecognizer */ -export default class SwipeRecognizer extends AttrRecognizer{ +export default class SwipeRecognizer extends AttrRecognizer { constructor() { - SwipeRecognizer.prototype.defaults = { - event: 'swipe', - threshold: 10, - velocity: 0.3, - direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL, - pointers: 1 - }; super(...arguments); } @@ -56,3 +49,11 @@ export default class SwipeRecognizer extends AttrRecognizer{ this.manager.emit(this.options.event, input); } } + +SwipeRecognizer.prototype.defaults = { + event: 'swipe', + threshold: 10, + velocity: 0.3, + direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL, + pointers: 1 +}; diff --git a/src/recognizers/tap.js b/src/recognizers/tap.js index fd26610c5..9ff9af277 100644 --- a/src/recognizers/tap.js +++ b/src/recognizers/tap.js @@ -22,15 +22,6 @@ import getDistance from '../inputjs/get-distance'; */ export default class TapRecognizer extends Recognizer { constructor() { - TapRecognizer.prototype.defaults = { - event: 'tap', - pointers: 1, - taps: 1, - interval: 300, // max time between the multi-tap taps - time: 250, // max time of the pointer to be down (like finger on the screen) - threshold: 9, // a minimal movement is ok, but keep it low - posThreshold: 10 // a multi-tap can be a bit off the initial position - }; super(...arguments); // previous time and center, @@ -119,3 +110,13 @@ export default class TapRecognizer extends Recognizer { } } } + +TapRecognizer.prototype.defaults = { + event: 'tap', + pointers: 1, + taps: 1, + interval: 300, // max time between the multi-tap taps + time: 250, // max time of the pointer to be down (like finger on the screen) + threshold: 9, // a minimal movement is ok, but keep it low + posThreshold: 10 // a multi-tap can be a bit off the initial position +};