-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(console): remove
lodash.uniqby
in favor of a leaner implement…
…ation
- Loading branch information
Showing
14 changed files
with
130 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
apps/wing-console/console/ui/src/features/explorer-pane/use-map.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
apps/wing-console/console/ui/src/features/hierarchy-pane/use-hierarchy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"root": true, | ||
"extends": ["plugin:@wingconsole/browser"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "@wingconsole/uniq-by", | ||
"version": "0.0.0", | ||
"private": true, | ||
"exports": "./src/index.ts", | ||
"types": "./src/index.ts", | ||
"sideEffects": false, | ||
"type": "module", | ||
"scripts": { | ||
"tsc": "tsc --build", | ||
"test": "vitest", | ||
"eslint": "eslint --ext .js,.cjs,.ts,.cts,.mts,.tsx --no-error-on-unmatched-pattern . --fix" | ||
}, | ||
"devDependencies": { | ||
"@wingconsole/eslint-plugin": "workspace:^", | ||
"@wingconsole/tsconfig": "workspace:^", | ||
"typescript": "^5.5.2", | ||
"vitest": "^1.6.0" | ||
}, | ||
"volta": { | ||
"extends": "../../../../package.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { uniqBy } from "./index.js"; | ||
|
||
test("deduplicates items using identity as iteratee", () => { | ||
expect(uniqBy([1, 2], (number) => number)).toEqual([1, 2]); | ||
expect(uniqBy([1, 2, 3, 1, 2], (number) => number)).toEqual([1, 2, 3]); | ||
}); | ||
|
||
test("deduplicates items using a custom iteratee", () => { | ||
expect( | ||
uniqBy( | ||
[ | ||
{ id: 1, name: "John" }, | ||
{ id: 2, name: "Sarah" }, | ||
{ id: 1, name: "Repeated" }, | ||
], | ||
(object) => object.id, | ||
), | ||
).toEqual([ | ||
{ id: 1, name: "John" }, | ||
{ id: 2, name: "Sarah" }, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Creates a duplicate-free version of an array, in which only the first occurrence of each element is kept. | ||
* The iteratee is invoked for each element in the array to generate the criterion by which uniqueness is computed. | ||
* | ||
* @param array - The array to inspect. | ||
* @param iteratee - The iteratee invoked per element. | ||
* @returns Returns the new duplicate-free array. | ||
*/ | ||
export function uniqBy<T, U>(array: T[], iteratee: (item: T) => U): T[] { | ||
const seen = new Set<U>(); | ||
return array.filter((item) => { | ||
const key = iteratee(item); | ||
if (seen.has(key)) { | ||
return false; | ||
} else { | ||
seen.add(key); | ||
return true; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@wingconsole/tsconfig", | ||
"include": ["src/**/*"] | ||
} |
Oops, something went wrong.