From 9393c54dc8690ed83db583b60d76eda27445ae1d Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Tue, 18 Dec 2018 16:30:51 +0000 Subject: [PATCH] fix: replace lodash.uniqby with internal fn --- package-lock.json | 5 ----- package.json | 1 - src/shared/getComponentOption.js | 4 ++-- src/shared/uniqBy.js | 8 ++++++++ 4 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 src/shared/uniqBy.js diff --git a/package-lock.json b/package-lock.json index 0342e05..14cd734 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6595,11 +6595,6 @@ "integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=", "dev": true }, - "lodash.uniqby": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz", - "integrity": "sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI=" - }, "lodash.uniqueid": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.uniqueid/-/lodash.uniqueid-4.0.1.tgz", diff --git a/package.json b/package.json index 40d4a15..eab7d49 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "dependencies": { "deepmerge": "^3.0.0", "lodash.isplainobject": "^4.0.6", - "lodash.uniqby": "^4.7.0", "lodash.uniqueid": "^4.0.1", "object-assign": "^4.1.1" }, diff --git a/src/shared/getComponentOption.js b/src/shared/getComponentOption.js index 82ce6a2..a0c8fa7 100644 --- a/src/shared/getComponentOption.js +++ b/src/shared/getComponentOption.js @@ -1,5 +1,5 @@ import deepmerge from 'deepmerge' -import uniqBy from 'lodash.uniqby' +import uniqBy from './uniqBy' import uniqueId from 'lodash.uniqueid' /** @@ -67,7 +67,7 @@ export default function getComponentOption (opts, result = {}) { return metaObject }) result.meta = uniqBy( - result.meta.reverse(), + result.meta, metaObject => metaObject.hasOwnProperty(tagIDKeyName) ? metaObject[tagIDKeyName] : uniqueId() ) } diff --git a/src/shared/uniqBy.js b/src/shared/uniqBy.js new file mode 100644 index 0000000..6d27a73 --- /dev/null +++ b/src/shared/uniqBy.js @@ -0,0 +1,8 @@ +export default function uniqBy (inputArray, predicate) { + return inputArray + .sort((a, b) => predicate(a) > predicate(b)) + .filter((x, i, arr) => i === arr.length - 1 + ? true + : predicate(x) !== predicate(arr[i + 1]) + ) +}