Skip to content

Commit

Permalink
chore: refactors 'defaults' back to a property
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunkathuria authored and arschmitz committed Sep 30, 2016
1 parent ed3b3ab commit caebb3d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 96 deletions.
11 changes: 2 additions & 9 deletions src/recognizerjs/recognizer-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import stateStr from './state-str';
*/
export default class Recognizer {
constructor(options) {
Recognizer.prototype.defaults = {};

this.options = assign({}, this.defaults, options || {});

this.id = uniqueId();
Expand All @@ -64,18 +66,9 @@ export default class Recognizer {
this.options.enable = ifUndefined(this.options.enable, true);

this.state = STATE_POSSIBLE;

this.simultaneous = {};
this.requireFail = [];
}
/**
* @private
* @virtual
* @type {Object}
*/
get defaults() {
return {};
}

/**
* @private
Expand Down
20 changes: 6 additions & 14 deletions src/recognizers/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@ import {
*/
export default class AttrRecognizer extends Recognizer {
constructor() {
super(...arguments);
}

/**
* @private
* @namespace
* @memberof AttrRecognizer
*/
get defaults() {
return {
AttrRecognizer.prototype.defaults = {
/**
* @private
* @type {Number}
* @default 1
*/
* @private
* @type {Number}
* @default 1
*/
pointers: 1
};
super(...arguments);
}

/**
Expand Down
17 changes: 4 additions & 13 deletions src/recognizers/pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,15 @@ import directionStr from '../recognizerjs/direction-str';
*/
export default class PanRecognizer extends AttrRecognizer {
constructor() {
super(...arguments);

this.pX = null;
this.pY = null;
}

/**
* @private
* @namespace
* @memberof PanRecognizer
*/
get defaults() {
return {
PanRecognizer.prototype.defaults = {
event: 'pan',
threshold: 10,
pointers: 1,
direction: DIRECTION_ALL
};
super(...arguments);
this.pX = null;
this.pY = null;
}

getTouchAction() {
Expand Down
12 changes: 2 additions & 10 deletions src/recognizers/pinch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@ import { STATE_BEGAN } from '../recognizerjs/recognizer-consts';
*/
export default class PinchRecognizer extends AttrRecognizer {
constructor() {
super(...arguments);
}

/**
* @private
* @namespace
* @memberof PinchRecognizer
*/
get defaults() {
return {
PinchRecognizer.prototype.defaults = {
event: 'pinch',
threshold: 0,
pointers: 2
};
super(...arguments);
}

getTouchAction() {
Expand Down
17 changes: 4 additions & 13 deletions src/recognizers/press.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,15 @@ import {
*/
export default class PressRecognizer extends Recognizer {
constructor() {
super(...arguments);

this._timer = null;
this._input = null;
}

/**
* @private
* @namespace
* @memberof PressRecognizer
*/
get defaults() {
return {
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;
}

getTouchAction() {
Expand Down
12 changes: 2 additions & 10 deletions src/recognizers/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@ import { STATE_BEGAN } from '../recognizerjs/recognizer-consts';
*/
export default class RotateRecognizer extends AttrRecognizer {
constructor() {
super(...arguments);
}

/**
* @private
* @namespace
* @memberof RotateRecognizer
*/
get defaults() {
return {
RotateRecognizer.prototype.defaults = {
event: 'rotate',
threshold: 0,
pointers: 2
};
super(...arguments);
}

getTouchAction() {
Expand Down
12 changes: 2 additions & 10 deletions src/recognizers/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@ import directionStr from '../recognizerjs/direction-str';
*/
export default class SwipeRecognizer extends AttrRecognizer{
constructor() {
super(...arguments);
}

/**
* @private
* @namespace
* @memberof SwipeRecognizer
*/
get defaults() {
return {
SwipeRecognizer.prototype.defaults = {
event: 'swipe',
threshold: 10,
velocity: 0.3,
direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
pointers: 1
};
super(...arguments);
}

getTouchAction() {
Expand Down
27 changes: 10 additions & 17 deletions src/recognizers/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ 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,
// used for tap counting
this.pTime = false;
Expand All @@ -33,23 +43,6 @@ export default class TapRecognizer extends Recognizer {
this.count = 0;
}

/**
* @private
* @namespace
* @memberof PinchRecognizer
*/
get defaults() {
return {
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
};
}

getTouchAction() {
return [TOUCH_ACTION_MANIPULATION];
}
Expand Down

0 comments on commit caebb3d

Please sign in to comment.