From 82ba3fab494f57bcee3528b5e3fa12df7b13f5e5 Mon Sep 17 00:00:00 2001 From: Tomas Korcak Date: Fri, 14 Aug 2015 19:54:03 +0200 Subject: [PATCH] Fixed eslint issues --- src/dat/utils/common.js | 100 ++++++++++++------------- src/dat/utils/css.js | 15 ++-- src/dat/utils/requestAnimationFrame.js | 13 ++-- 3 files changed, 63 insertions(+), 65 deletions(-) diff --git a/src/dat/utils/common.js b/src/dat/utils/common.js index 25b7fa9..b03228b 100644 --- a/src/dat/utils/common.js +++ b/src/dat/utils/common.js @@ -11,8 +11,8 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -var ARR_EACH = Array.prototype.forEach; -var ARR_SLICE = Array.prototype.slice; +const ARR_EACH = Array.prototype.forEach; +const ARR_SLICE = Array.prototype.slice; /** * Band-aid methods for things that should be a lot easier in JavaScript. @@ -20,118 +20,112 @@ var ARR_SLICE = Array.prototype.slice; * http://documentcloud.github.com/underscore/ */ -var Common = { - +const Common = { BREAK: {}, - extend: function (target) { - - this.each(ARR_SLICE.call(arguments, 1), function (obj) { - - for (var key in obj) - if (!this.isUndefined(obj[key])) + extend: function(target) { + this.each(ARR_SLICE.call(arguments, 1), function(obj) { + for (const key in obj) { + if (!this.isUndefined(obj[key])) { target[key] = obj[key]; - + } + } }, this); return target; - }, - defaults: function (target) { - - this.each(ARR_SLICE.call(arguments, 1), function (obj) { - - for (var key in obj) - if (this.isUndefined(target[key])) + defaults: function(target) { + this.each(ARR_SLICE.call(arguments, 1), function(obj) { + for (const key in obj) { + if (this.isUndefined(target[key])) { target[key] = obj[key]; - + } + } }, this); return target; - }, - compose: function () { - var toCall = ARR_SLICE.call(arguments); - return function () { - var args = ARR_SLICE.call(arguments); - for (var i = toCall.length - 1; i >= 0; i--) { + compose: function() { + const toCall = ARR_SLICE.call(arguments); + return function() { + let args = ARR_SLICE.call(arguments); + for (let i = toCall.length - 1; i >= 0; i--) { args = [toCall[i].apply(this, args)]; } return args[0]; - } + }; }, - each: function (obj, itr, scope) { - - if (!obj) return; + each: function(obj, itr, scope) { + if (!obj) { + return; + } if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) { - obj.forEach(itr, scope); - } else if (obj.length === obj.length + 0) { // Is number but not NaN - - for (var key = 0, l = obj.length; key < l; key++) - if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) + let key; + for (key = 0, l = obj.length; key < l; key++) { + if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) { return; - + } + } } else { - - for (var key in obj) - if (itr.call(scope, obj[key], key) === this.BREAK) + for (const key in obj) { + if (itr.call(scope, obj[key], key) === this.BREAK) { return; - + } + } } - }, - defer: function (fnc) { + defer: function(fnc) { setTimeout(fnc, 0); }, - toArray: function (obj) { + toArray: function(obj) { if (obj.toArray) return obj.toArray(); return ARR_SLICE.call(obj); }, - isUndefined: function (obj) { + isUndefined: function(obj) { return obj === undefined; }, - isNull: function (obj) { + isNull: function(obj) { return obj === null; }, - isNaN: function (obj) { - return obj !== obj; + isNaN: function(obj) { + return isNaN(obj); }, - isArray: Array.isArray || function (obj) { + isArray: Array.isArray || function(obj) { return obj.constructor === Array; }, - isObject: function (obj) { + isObject: function(obj) { return obj === Object(obj); }, - isNumber: function (obj) { + isNumber: function(obj) { return obj === obj + 0; }, - isString: function (obj) { + isString: function(obj) { return obj === obj + ''; }, - isBoolean: function (obj) { + isBoolean: function(obj) { return obj === false || obj === true; }, - isFunction: function (obj) { + isFunction: function(obj) { return Object.prototype.toString.call(obj) === '[object Function]'; } }; -module.exports = Common; \ No newline at end of file +export default Common; diff --git a/src/dat/utils/css.js b/src/dat/utils/css.js index 54a58ef..3a5c479 100644 --- a/src/dat/utils/css.js +++ b/src/dat/utils/css.js @@ -12,19 +12,20 @@ */ module.exports = { - load: function (url, doc) { - doc = doc || document; - var link = doc.createElement('link'); + load: function(url, indoc) { + const doc = indoc || document; + const link = doc.createElement('link'); link.type = 'text/css'; link.rel = 'stylesheet'; link.href = url; doc.getElementsByTagName('head')[0].appendChild(link); }, - inject: function (css, doc) { - doc = doc || document; - var injected = document.createElement('style'); + + inject: function(css, indoc) { + const doc = indoc || document; + const injected = document.createElement('style'); injected.type = 'text/css'; injected.innerHTML = css; doc.getElementsByTagName('head')[0].appendChild(injected); } -}; \ No newline at end of file +}; diff --git a/src/dat/utils/requestAnimationFrame.js b/src/dat/utils/requestAnimationFrame.js index c95381d..147925a 100644 --- a/src/dat/utils/requestAnimationFrame.js +++ b/src/dat/utils/requestAnimationFrame.js @@ -11,13 +11,16 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -module.exports = function () { +export default function() { + function requestAnimationFrame(callback) { + // TODO: Get rid of window + window.setTimeout(callback, 1000 / 60); + } + return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || - function (callback, element) { - window.setTimeout(callback, 1000 / 60); - }; -}; + requestAnimationFrame; +}