From c337e873b455ba2fabc91ebc7b907fd41fbeffc4 Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Thu, 16 Jun 2016 21:14:33 +0530 Subject: [PATCH] style(arrow functions): adds the nice ES6 arrow-function syntax for callbacks --- .jscsrc | 3 ++- src/input/touch.js | 2 +- src/main.js | 2 +- src/manager.js | 8 ++++---- src/recognizers/press.js | 2 +- src/recognizers/tap.js | 4 ++-- src/touchactionjs/get-touchaction-props.js | 4 ++-- src/touchactionjs/touchaction-constructor.js | 2 +- src/utils/add-event-listeners.js | 2 +- src/utils/extend.js | 2 +- src/utils/merge.js | 2 +- src/utils/remove-event-listeners.js | 2 +- src/utils/unique-array.js | 2 +- 13 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.jscsrc b/.jscsrc index f3c50dc51..34c401bc6 100644 --- a/.jscsrc +++ b/.jscsrc @@ -5,5 +5,6 @@ "tests/**/assets", "node_modules/**" ], - "disallowConstOutsideModuleScope": false + "disallowConstOutsideModuleScope": false, + "requireArrowFunctions": true, } diff --git a/src/input/touch.js b/src/input/touch.js index 5e3708b82..9d02b1f8b 100644 --- a/src/input/touch.js +++ b/src/input/touch.js @@ -74,7 +74,7 @@ function getTouches(ev, type) { let { target } = this; // get target touches from touches - targetTouches = allTouches.filter(function(touch) { + targetTouches = allTouches.filter((touch) => { return hasParent(touch.target, target); }); diff --git a/src/main.js b/src/main.js index 2672503c6..0baa47e0e 100644 --- a/src/main.js +++ b/src/main.js @@ -128,7 +128,7 @@ freeGlobal.Hammer = Hammer; /* jshint ignore:start */ if (typeof define === 'function' && define.amd) { - define(function() { + define(() => { return Hammer; }); } else if (typeof module !== 'undefined' && module.exports) { diff --git a/src/manager.js b/src/manager.js index cb2b602b1..9a3de6096 100644 --- a/src/manager.js +++ b/src/manager.js @@ -41,7 +41,7 @@ function Manager(element, options) { toggleCssProps(this, true); - each(this.options.recognizers, function(item) { + each(this.options.recognizers, (item) => { let recognizer = this.add(new (item[0])(item[1])); item[2] && recognizer.recognizeWith(item[2]); item[3] && recognizer.requireFailure(item[3]); @@ -226,7 +226,7 @@ Manager.prototype = { } let { handlers } = this; - each(splitStr(events), function(event) { + each(splitStr(events), (event) => { handlers[event] = handlers[event] || []; handlers[event].push(handler); }); @@ -245,7 +245,7 @@ Manager.prototype = { } let { handlers } = this; - each(splitStr(events), function(event) { + each(splitStr(events), (event) => { if (!handler) { delete handlers[event]; } else { @@ -311,7 +311,7 @@ function toggleCssProps(manager, add) { return; } let prop; - each(manager.options.cssProps, function(value, name) { + each(manager.options.cssProps, (value, name) => { prop = prefixed(element.style, name); if (add) { manager.oldCssProps[prop] = element.style[prop]; diff --git a/src/recognizers/press.js b/src/recognizers/press.js index f8ee3271e..60f6153db 100644 --- a/src/recognizers/press.js +++ b/src/recognizers/press.js @@ -58,7 +58,7 @@ inherit(PressRecognizer, Recognizer, { this.reset(); } else if (input.eventType & INPUT_START) { this.reset(); - this._timer = setTimeoutContext(function() { + this._timer = setTimeoutContext(() => { this.state = STATE_RECOGNIZED; this.tryEmit(); }, options.time, this); diff --git a/src/recognizers/tap.js b/src/recognizers/tap.js index e11a981e4..774f6af1b 100644 --- a/src/recognizers/tap.js +++ b/src/recognizers/tap.js @@ -97,7 +97,7 @@ inherit(TapRecognizer, Recognizer, { if (!this.hasRequireFailures()) { return STATE_RECOGNIZED; } else { - this._timer = setTimeoutContext(function() { + this._timer = setTimeoutContext(() => { this.state = STATE_RECOGNIZED; this.tryEmit(); }, options.interval, this); @@ -109,7 +109,7 @@ inherit(TapRecognizer, Recognizer, { }, failTimeout() { - this._timer = setTimeoutContext(function() { + this._timer = setTimeoutContext(() => { this.state = STATE_FAILED; }, this.options.interval, this); return STATE_FAILED; diff --git a/src/touchactionjs/get-touchaction-props.js b/src/touchactionjs/get-touchaction-props.js index 3b695fd69..86f9fb3ad 100644 --- a/src/touchactionjs/get-touchaction-props.js +++ b/src/touchactionjs/get-touchaction-props.js @@ -6,11 +6,11 @@ export default function getTouchActionProps() { } let touchMap = {}; let cssSupports = window.CSS && window.CSS.supports; - ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function(val) { + ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach((val) => { // If css.supports is not supported but there is native touch-action assume it supports // all values. This is the case for IE 10 and 11. - touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true; + return touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true; }); return touchMap; } diff --git a/src/touchactionjs/touchaction-constructor.js b/src/touchactionjs/touchaction-constructor.js index 79f417bd9..f8425bb05 100644 --- a/src/touchactionjs/touchaction-constructor.js +++ b/src/touchactionjs/touchaction-constructor.js @@ -62,7 +62,7 @@ TouchAction.prototype = { */ compute() { let actions = []; - each(this.manager.recognizers, function(recognizer) { + each(this.manager.recognizers, (recognizer) => { if (boolOrFn(recognizer.options.enable, [recognizer])) { actions = actions.concat(recognizer.getTouchAction()); } diff --git a/src/utils/add-event-listeners.js b/src/utils/add-event-listeners.js index bbfad9ede..99b2da80c 100644 --- a/src/utils/add-event-listeners.js +++ b/src/utils/add-event-listeners.js @@ -8,7 +8,7 @@ import splitStr from './split-str'; * @param {Function} handler */ export default function addEventListeners(target, types, handler) { - each(splitStr(types), function(type) { + each(splitStr(types), (type) => { target.addEventListener(type, handler, false); }); } diff --git a/src/utils/extend.js b/src/utils/extend.js index 0b41be4c5..b3aa2372f 100644 --- a/src/utils/extend.js +++ b/src/utils/extend.js @@ -8,7 +8,7 @@ import deprecate from './deprecate'; * @param {Boolean} [merge=false] * @returns {Object} dest */ -const extend = deprecate(function extend(dest, src, merge) { +const extend = deprecate((dest, src, merge) => { let keys = Object.keys(src); let i = 0; while (i < keys.length) { diff --git a/src/utils/merge.js b/src/utils/merge.js index 333df4f86..015447d9c 100644 --- a/src/utils/merge.js +++ b/src/utils/merge.js @@ -8,7 +8,7 @@ import extend from './extend'; * @param {Object} src * @returns {Object} dest */ -const merge = deprecate(function merge(dest, src) { +const merge = deprecate((dest, src) => { return extend(dest, src, true); }, 'merge', 'Use `assign`.'); diff --git a/src/utils/remove-event-listeners.js b/src/utils/remove-event-listeners.js index 56fa66484..a26898743 100644 --- a/src/utils/remove-event-listeners.js +++ b/src/utils/remove-event-listeners.js @@ -8,7 +8,7 @@ import splitStr from './split-str'; * @param {Function} handler */ export default function removeEventListeners(target, types, handler) { - each(splitStr(types), function(type) { + each(splitStr(types), (type) => { target.removeEventListener(type, handler, false); }); } diff --git a/src/utils/unique-array.js b/src/utils/unique-array.js index de5144ce1..36a95aeb8 100644 --- a/src/utils/unique-array.js +++ b/src/utils/unique-array.js @@ -26,7 +26,7 @@ export default function uniqueArray(src, key, sort) { if (!key) { results = results.sort(); } else { - results = results.sort(function sortUniqueArray(a, b) { + results = results.sort((a, b) => { return a[key] > b[key]; }); }