diff --git a/src/style-spec/group_by_layout.js b/src/style-spec/group_by_layout.js index 1e29956b38d..4041ea43b45 100644 --- a/src/style-spec/group_by_layout.js +++ b/src/style-spec/group_by_layout.js @@ -1,12 +1,35 @@ 'use strict'; -const refProperties = require('./util/ref_properties'), - stringify = require('fast-stable-stringify'); +const refProperties = require('./util/ref_properties'); -function key(layer) { - return stringify(refProperties.map((k) => { - return layer[k]; - })); +function stringify(obj) { + const type = typeof obj; + if (type === 'number' || type === 'string' || obj === undefined || obj === null) + return JSON.stringify(obj); + + if (Array.isArray(obj)) { + let str = '['; + for (const val of obj) { + str += `${stringify(val)},`; + } + return `${str}]`; + } + + const keys = Object.keys(obj).sort(); + + let str = '{'; + for (let i = 0; i < keys.length; i++) { + str += `${JSON.stringify(keys[i])}:${stringify(obj[keys[i]])},`; + } + return `${str}}`; +} + +function getKey(layer) { + let key = ''; + for (const k of refProperties) { + key += `/${stringify(layer[k])}`; + } + return key; } module.exports = groupByLayout; @@ -29,7 +52,7 @@ function groupByLayout(layers) { const groups = {}; for (let i = 0; i < layers.length; i++) { - const k = key(layers[i]); + const k = getKey(layers[i]); let group = groups[k]; if (!group) { group = groups[k] = []; diff --git a/src/style-spec/package.json b/src/style-spec/package.json index 7bd66843825..7e20459b3ae 100644 --- a/src/style-spec/package.json +++ b/src/style-spec/package.json @@ -22,7 +22,6 @@ }, "dependencies": { "csscolorparser": "~1.0.2", - "fast-stable-stringify": "^0.1.1", "jsonlint-lines-primitives": "~1.6.0", "lodash.isequal": "^3.0.4", "minimist": "0.0.8", diff --git a/yarn.lock b/yarn.lock index 3d819383777..821857d1fec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2682,7 +2682,7 @@ glob-stream@^5.3.2: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^5.0.3: +glob@^5.0.14, glob@^5.0.3: version "5.0.15" resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1" dependencies: