Skip to content

Commit

Permalink
Update for new xo linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
orangemug committed May 21, 2020
1 parent c8b6d6a commit fe44a79
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const EventEmitter = require('events');
const icepick = require('icepick');

const INVALID_ROOT_KEYS = ['layers', 'sources'];
const INVALID_ROOT_KEYS = new Set(['layers', 'sources']);

const VALID_HOOKS = ['validate'];

Expand All @@ -12,20 +12,20 @@ const DEFAULT_STYLE = {
};

class IcepickStyle extends EventEmitter {
constructor(inputStyle, opts = {}) {
constructor(inputStyle, options = {}) {
super();
opts = {
options = {
maxHistoryLength: 100,
hooks: {},
...opts
...options
};

this._hooks = {};
this._maxHistoryLength = opts.maxHistoryLength;
this._maxHistoryLength = options.maxHistoryLength;

VALID_HOOKS.forEach(key => {
if (opts.hooks[key] && Array.isArray(opts.hooks[key])) {
this._hooks[key] = [].concat(opts.hooks[key]);
if (options.hooks[key] && Array.isArray(options.hooks[key])) {
this._hooks[key] = [].concat(options.hooks[key]);
} else {
this._hooks[key] = [];
}
Expand Down Expand Up @@ -84,7 +84,7 @@ class IcepickStyle extends EventEmitter {
}

_assertValidHook(key) {
if (VALID_HOOKS.indexOf(key) < 0) {
if (!VALID_HOOKS.includes(key)) {
throw new Error('Invalid hook type: ' + key);
}
}
Expand All @@ -104,15 +104,15 @@ class IcepickStyle extends EventEmitter {
});
}

merge(obj) {
const newDoc = icepick.merge(this.current, obj);
merge(object) {
const newDoc = icepick.merge(this.current, object);
this._pushHistory(newDoc);
}

replace(obj) {
replace(object) {
const newDoc = icepick.replace(this.current, {
...DEFAULT_STYLE,
...obj
...object
});
this._pushHistory(newDoc);
}
Expand Down Expand Up @@ -148,20 +148,20 @@ class IcepickStyle extends EventEmitter {
/*
* Style functions
*/
addRoot(key, obj) {
if (INVALID_ROOT_KEYS.indexOf(key) > -1) {
addRoot(key, object) {
if (INVALID_ROOT_KEYS.has(key)) {
throw new Error(`Can't add ${key} use add* methods instead`);
}

if (Object.prototype.hasOwnProperty.call(this.current, key)) {
throw new Error('Already has root element');
}

return this.modifyRoot(key, obj);
return this.modifyRoot(key, object);
}

modifyRoot(key, obj) {
if (INVALID_ROOT_KEYS.indexOf(key) > -1) {
modifyRoot(key, object) {
if (INVALID_ROOT_KEYS.has(key)) {
throw new Error(`Can't modify ${key} use modify* methods instead`);
}

Expand All @@ -172,18 +172,18 @@ class IcepickStyle extends EventEmitter {
newDoc = icepick.setIn(
this.current,
[key],
icepick.replace(this.current[key], obj)
icepick.replace(this.current[key], object)
);
} else {
newDoc = icepick.setIn(this.current, [key], obj);
newDoc = icepick.setIn(this.current, [key], object);
}

this._pushHistory(newDoc);
return this;
}

removeRoot(key) {
if (INVALID_ROOT_KEYS.indexOf(key) > -1) {
if (INVALID_ROOT_KEYS.has(key)) {
throw new Error(`Can't remove ${key} use remove* methods instead`);
}

Expand Down Expand Up @@ -264,8 +264,8 @@ class IcepickStyle extends EventEmitter {
const doc = this.current;
const {layers} = doc;
const layer = layers[idx];
const tmpLayers = icepick.splice(layers, idx, 1);
const newLayers = icepick.splice(tmpLayers, newIdx, 0, layer);
const temporaryLayers = icepick.splice(layers, idx, 1);
const newLayers = icepick.splice(temporaryLayers, newIdx, 0, layer);

const newDoc = icepick.setIn(
doc,
Expand Down

0 comments on commit fe44a79

Please sign in to comment.