Skip to content

Commit

Permalink
Merge pull request #7 from mgljs-contrib/fix/update-deps-20200521
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
orangemug authored May 21, 2020
2 parents ac83795 + fe44a79 commit 640cfb8
Show file tree
Hide file tree
Showing 3 changed files with 2,509 additions and 1,301 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
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"main": "lib/index.js",
"scripts": {
"build": "exit 0",
"test": "npm run test:lint && npm run test:unit",
"test:ci": "npm run test:lint && npm run test:ci:unit",
"test:lint": "xo",
Expand All @@ -16,11 +17,12 @@
"icepick": "github:orangemug/icepick#feature/added-replace"
},
"devDependencies": {
"@mapbox/mapbox-gl-style-spec": "^13.6.0",
"coveralls": "^3.0.3",
"mocha": "^6.1.4",
"nyc": "^14.1.0",
"xo": "^0.24.0"
"@mapbox/mapbox-gl-style-spec": "^13.15.0",
"coveralls": "^3.1.0",
"mocha": "^7.1.2",
"node": "^14.2.0",
"nyc": "^15.0.1",
"xo": "^0.30.0"
},
"nyc": {
"check-coverage": true,
Expand Down
Loading

0 comments on commit 640cfb8

Please sign in to comment.