From 19ad1af0a41321f9def3812598517629b12977ed Mon Sep 17 00:00:00 2001 From: Jason Wohlgemuth Date: Sat, 19 Aug 2017 20:32:30 -0500 Subject: [PATCH] Cleared more lint issues by reducing complexity and add inline disables --- dist/voxelcss.js | 2 +- lib/events.js | 132 +++++++++++++++++++++++------------------------ 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/dist/voxelcss.js b/dist/voxelcss.js index dfd5b92..12574ea 100644 --- a/dist/voxelcss.js +++ b/dist/voxelcss.js @@ -1 +1 @@ -"use strict";var _slicedToArray=function(){function t(t,e){var r=[],a=!0,o=!1,s=void 0;try{for(var n,i=t[Symbol.iterator]();!(a=(n=i.next()).done)&&(r.push(n.value),!(e&&r.length===e));a=!0);}catch(t){o=!0,s=t}finally{try{!a&&i["return"]&&i["return"]()}finally{if(o)throw s}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function _defineProperty(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);el?1:c(1,e(1-m/(x/2))+g(f/p,6));return 1-(v*h+b)};a=l(0,a-v([0,0,-1])),r=l(0,r-v([0,0,1])),o=l(0,o-v([-1,0,0])),s=l(0,s-v([1,0,0])),i=l(0,i-v([0,1,0])),m=l(0,m-v([0,-1,0]))});var f={front:r,back:a,left:o,right:s,top:i,bottom:m};n(f).forEach(function(t){Y[t].shader.style.opacity=f[t]})},setMesh:t,getMesh:function getMesh(){return D},getDomElement:function getDomElement(){return Z},getAnimatedElement:function getAnimatedElement(){return B}});function t(){var t=0"};r(this,{add:s,remove:n,clear:i,getScene:function getScene(){return t},getVoxels:function getVoxels(){return x},import:l,export:m,load:function load(){return l(localStorage.getItem(g())||"[]")},isSaved:function isSaved(){return!!localStorage.getItem(g())},save:function save(){return localStorage.setItem(g(),m())},deleteSave:function deleteSave(){return localStorage.setItem(g(),"")}})}},{"./Mesh":6,"./Voxel":8}],10:[function(t,e){"use strict";function r(t,e){for(var a=t.length,o=t[0].length,s=e[0].length,n=Array(a),m=0;m=r&&(t=null),e}},l=function(t){return function(e){return null===e?void 0:e[t]}},c=function(t){var e=l("length")(t);return"number"==typeof e&&0<=e&&e<=9007199254740991},x=function(t){var e="undefined"==typeof t?"undefined":_typeof(t);return"function"===e||"object"===e&&!!t},g=function(t){return!(null!==t)||(c(t)&&(Array.isArray(t)||"string"==typeof t)?0===t.length:0===Object.keys(t).length)},f=function(t,e,r,a){try{t.on(e,r,a)}catch(t){return t}},d=void 0,p=function(t,e,r,a){if(r){var o=t[e]||(t[e]=[]),s=a.context,n=a.ctx,i=a.listening;n=s||n,i&&i.count++,o.push({callback:r,context:s,ctx:n,listening:i})}return t},h=function(t,e,r,a){if(t){var o=a.context,s=a.listeners,n=0,i=void 0;if(!e&&!o&&!r){for(i=x(s)?Object.keys(s):[],i;nl?1:c(1,e(1-m/(x/2))+g(f/p,6));return 1-(v*h+b)};a=l(0,a-v([0,0,-1])),r=l(0,r-v([0,0,1])),o=l(0,o-v([-1,0,0])),s=l(0,s-v([1,0,0])),i=l(0,i-v([0,1,0])),m=l(0,m-v([0,-1,0]))});var f={front:r,back:a,left:o,right:s,top:i,bottom:m};n(f).forEach(function(t){Y[t].shader.style.opacity=f[t]})},setMesh:t,getMesh:function getMesh(){return D},getDomElement:function getDomElement(){return Z},getAnimatedElement:function getAnimatedElement(){return B}});function t(){var t=0"};r(this,{add:s,remove:n,clear:i,getScene:function getScene(){return t},getVoxels:function getVoxels(){return x},import:l,export:m,load:function load(){return l(localStorage.getItem(g())||"[]")},isSaved:function isSaved(){return!!localStorage.getItem(g())},save:function save(){return localStorage.setItem(g(),m())},deleteSave:function deleteSave(){return localStorage.setItem(g(),"")}})}},{"./Mesh":6,"./Voxel":8}],10:[function(t,e){"use strict";function r(t,e){for(var a=t.length,o=t[0].length,s=e[0].length,n=Array(a),m=0;m=r&&(t=null),e}},l=function(t){return function(e){return null===e?void 0:e[t]}},c=function(t){var e=l("length")(t);return"number"==typeof e&&0<=e&&e<=Number.MAX_SAFE_INTEGER},x=function(t){var e="undefined"==typeof t?"undefined":_typeof(t);return"function"===e||"object"===e&&!!t},g=function(t){return!(null!==t)||(c(t)&&(Array.isArray(t)||"string"==typeof t)?0===t.length:0===Object.keys(t).length)},f=function(t,e,r,a){try{t.on(e,r,a)}catch(t){return t}},d=void 0,p=function(t,e,r,a){if(r){var o=t[e]||(t[e]=[]),s=a.context,n=a.ctx,i=a.listening;n=s||n,i&&i.count++,o.push({callback:r,context:s,ctx:n,listening:i})}return t},h=function(t,e,r,a){if(t){var o=a.context,s=a.listeners,n=void 0;return e||o||r?(n=e?[e]:Object.keys(t),n.forEach(function(e){var a=t[e];if(a){var s=[];a.forEach(function(t){if(r&&r!==t.callback&&r!==t.callback._callback||o&&o!==t.context)s.push(t);else{var a=t.listening;a&&a.off(e,r)}}),s.length?t[e]=s:delete t[e]}}),t):(n=x(s)?Object.keys(s):[],void n.forEach(function(t){return s[t].cleanup()}))}},b=function(t,e,r,a){if(r){var o=t[e]=m(function(){a(e,o),r.apply(this,arguments)});o._callback=r}return t},v=function(t,e,r,a,o){var n=r&&"object"===("undefined"==typeof r?"undefined":_typeof(r));if(n){var i=void 0!==a&&"context"in o&&void 0===o.context;i&&(o.context=a),Object.keys(r).forEach(function(a){e=v(t,e,a,r[a],o)})}else r&&s.test(r)?r.split(s).forEach(function(r){e=t(e,r,a,o)}):e=t(e,r,a,o);return e},k=function(t,e){var r,a=-1,o=t.length,s=_slicedToArray(e,3),n=s[0],i=s[1],m=s[2];switch(e.length){case 0:for(;++a obj => (obj === null ? void 0 : obj[key]); let isArrayLike = collection => { let length = property('length')(collection); - return typeof length === 'number' && length >= 0 && length <= MAX_ARRAY_INDEX; + return typeof length === 'number' && length >= 0 && length <= Number.MAX_SAFE_INTEGER; }; let isObject = obj => { let type = typeof obj; @@ -39,7 +38,6 @@ let tryCatchOn = (obj, name, callback, context) => { } }; -// A private global variable to share between listeners and listenees. let _listening; let onApi = (events, name, callback, options) => { if (callback) { @@ -54,41 +52,37 @@ let onApi = (events, name, callback, options) => { let offApi = (events, name, callback, options) => { if (!events) {return;} let {context, listeners} = options; - let i = 0; let names; if (!name && !context && !callback) { names = isObject(listeners) ? Object.keys(listeners) : []; - for (names; i < names.length; i++) { - listeners[names[i]].cleanup(); - } + names.forEach(name => (listeners[name].cleanup())); return; } names = name ? [name] : Object.keys(events); - for (; i < names.length; i++) { - name = names[i]; - var handlers = events[name]; - if (!handlers) {break;} - var remaining = []; - for (var j = 0; j < handlers.length; j++) { - var handler = handlers[j]; - if (callback && callback !== handler.callback && callback !== handler.callback._callback || context && context !== handler.context) { - remaining.push(handler); + names.forEach(name => { + let handlers = events[name]; + if (handlers) { + let remaining = []; + handlers.forEach(handler => { + if (callback && callback !== handler.callback && callback !== handler.callback._callback || context && context !== handler.context) { + remaining.push(handler); + } else { + let listening = handler.listening; + if (listening) {listening.off(name, callback);} + } + }); + if (remaining.length) { + events[name] = remaining; } else { - var listening = handler.listening; - if (listening) {listening.off(name, callback);} + delete events[name]; } } - if (remaining.length) { - events[name] = remaining; - } else { - delete events[name]; - } - } + }); return events; }; let onceMap = function(map, name, callback, offer) { if (callback) { - var _once = map[name] = once(function() { + let _once = map[name] = once(function() { offer(name, _once); callback.apply(this, arguments); }); @@ -97,29 +91,30 @@ let onceMap = function(map, name, callback, offer) { return map; }; let eventsApi = (iteratee, events, name, callback, opts) => { - let i = 0; - let names; - if (name && typeof name === 'object') {// event maps - if (callback !== void 0 && 'context' in opts && opts.context === void 0) {opts.context = callback;} - for (names = Object.keys(name); i < names.length ; i++) { - events = eventsApi(iteratee, events, names[i], name[names[i]], opts); + let isEventMap = (name && typeof name === 'object'); + if (isEventMap) { + let hasContextNoCallback = (callback !== void 0 && 'context' in opts && opts.context === void 0); + if (hasContextNoCallback) { + opts.context = callback; } + Object.keys(name).forEach(val => { + events = eventsApi(iteratee, events, val, name[val], opts); + }); } else if (name && eventSplitter.test(name)) {// space-separated event names by delegating them individually - for (names = name.split(eventSplitter); i < names.length; i++) { - events = iteratee(events, names[i], callback, opts); - } - } else {// standard events. + name.split(eventSplitter).forEach(name => { + events = iteratee(events, name, callback, opts); + }); + } else {// standard events events = iteratee(events, name, callback, opts); } return events; }; +/* eslint-disable complexity */ let triggerEvents = (events, args) => { - var ev; - var i = -1; - var l = events.length; - var a1 = args[0]; - var a2 = args[1]; - var a3 = args[2]; + let ev; + let i = -1; + let l = events.length; + let [a1, a2, a3] = args; switch (args.length) { case 0: while (++i < l) {(ev = events[i]).callback.call(ev.ctx);} break; case 1: while (++i < l) {(ev = events[i]).callback.call(ev.ctx, a1);} break; @@ -128,10 +123,11 @@ let triggerEvents = (events, args) => { default: while (++i < l) {(ev = events[i]).callback.apply(ev.ctx, args);} } }; +/* eslint-enable complexity */ let triggerApi = (objEvents, name, callback, args) => { if (objEvents) { - var events = objEvents[name]; - var allEvents = objEvents.all; + let events = objEvents[name]; + let allEvents = objEvents.all; if (events && allEvents) {allEvents = allEvents.slice();} if (events) {triggerEvents(events, args);} if (allEvents) {triggerEvents(allEvents, [name].concat(args));} @@ -147,7 +143,7 @@ let Events = { listening: _listening }); if (_listening) { - var listeners = this._listeners || (this._listeners = {}); + let listeners = this._listeners || (this._listeners = {}); listeners[_listening.id] = _listening; _listening.interop = false; } @@ -162,28 +158,30 @@ let Events = { return this; }, once: function(name, callback, context) { - var events = eventsApi(onceMap, {}, name, callback, this.off.bind(this)); + let events = eventsApi(onceMap, {}, name, callback, this.off.bind(this)); if (typeof name === 'string' && context === null) {callback = void 0;} return this.on(events, callback, context); }, trigger: function(name) { - if (!this._events) {return this;} - var length = Math.max(0, arguments.length - 1); - var args = Array(length); - for (var i = 0; i < length; i++) {args[i] = arguments[i + 1];} - eventsApi(triggerApi, this._events, name, void 0, args); + if (this._events) { + let length = Math.max(0, arguments.length - 1); + let args = Array(length); + for (var i = 0; i < length; i++) {args[i] = arguments[i + 1];} + eventsApi(triggerApi, this._events, name, void 0, args); + } return this; }, + /* eslint-disable complexity */ listenTo: function(obj, name, callback) { if (obj) { - var id = obj._listenId || (obj._listenId = uniqueId('l')); - var listeningTo = this._listeningTo || (this._listeningTo = {}); - var listening = _listening = listeningTo[id]; + let id = obj._listenId || (obj._listenId = uniqueId('l')); + let listeningTo = this._listeningTo || (this._listeningTo = {}); + let listening = _listening = listeningTo[id]; if (!listening) { this._listenId || (this._listenId = uniqueId('l')); listening = _listening = listeningTo[id] = new Listening(this, obj); } - var error = tryCatchOn(obj, name, callback, this); + let error = tryCatchOn(obj, name, callback, this); _listening = void 0; if (error) {throw error;} // If the target obj is not Backbone.Events, track events manually. @@ -191,25 +189,27 @@ let Events = { } return this; }, + /* eslint-enable complexity */ listenToOnce: function(obj, name, callback) { - var events = eventsApi(onceMap, {}, name, callback, this.stopListening.bind(this, obj)); + let events = eventsApi(onceMap, {}, name, callback, this.stopListening.bind(this, obj)); return this.listenTo(obj, events); }, stopListening: function(obj, name, callback) { - var listeningTo = this._listeningTo; - if (!listeningTo) {return this;} - var ids = obj ? [obj._listenId] : Object.keys(listeningTo); - for (var i = 0; i < ids.length; i++) { - var listening = listeningTo[ids[i]]; - if (!listening) {break;} - listening.obj.off(name, callback, this); - if (listening.interop) {listening.off(name, callback);} + let listeningTo = this._listeningTo; + if (listeningTo) { + let ids = obj ? [obj._listenId] : Object.keys(listeningTo); + ids.forEach(id => { + let listening = listeningTo[id]; + if (listening) { + listening.obj.off(name, callback, this); + if (listening.interop) {listening.off(name, callback);} + } + }); + if (isEmpty(listeningTo)) {this._listeningTo = void 0;} } - if (isEmpty(listeningTo)) {this._listeningTo = void 0;} return this; } }; - function Listening(listener, obj) { this.id = listener._listenId; this.listener = listener; @@ -221,7 +221,7 @@ function Listening(listener, obj) { assign(Listening.prototype, { on: Events.on, off: function(name, callback) { - var cleanup; + let cleanup; if (this.interop) { this._events = eventsApi(offApi, this._events, name, callback, { context: void 0,