-
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.
feat(console): remove
lodash.*
in favor of leaner implementations (#…
…6978) The following packages are removed: - `lodash.debounce` and `@types/lodash.debounce` - `lodash.escape` and `@types/lodash.escape` - `lodash.throttle` and `@types/lodash.throttle` - `lodash.uniq` and `@types/lodash.uniq`
- Loading branch information
Showing
24 changed files
with
111 additions
and
108 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
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
2 changes: 1 addition & 1 deletion
2
apps/wing-console/console/ui/src/features/explorer-pane/use-map.bridge-connections.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
2 changes: 1 addition & 1 deletion
2
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
2 changes: 1 addition & 1 deletion
2
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ing-console/packages/uniq-by/package.json → ...g-console/packages/utilities/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
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,25 @@ | ||
export function debounce<T extends (...arguments_: any[]) => void>( | ||
function_: T, | ||
wait: number, | ||
immediate: boolean = false, | ||
): (...arguments_: Parameters<T>) => void { | ||
let timeout: NodeJS.Timeout | undefined; | ||
|
||
return (...arguments_: Parameters<T>): void => { | ||
const later = () => { | ||
timeout = undefined; | ||
if (!immediate) { | ||
function_(...arguments_); | ||
} | ||
}; | ||
|
||
const callNow = immediate && !timeout; | ||
|
||
clearTimeout(timeout); | ||
timeout = setTimeout(later, wait); | ||
|
||
if (callNow) { | ||
function_(...arguments_); | ||
} | ||
}; | ||
} |
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,9 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { escapeHtml } from "./escape-html.js"; | ||
|
||
test("escapes html characters", () => { | ||
expect(escapeHtml(`<div class="class" id='1'>Wing & Console</div>`)).toEqual( | ||
`<div class="class" id='1'>Wing & Console</div>`, | ||
); | ||
}); |
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,22 @@ | ||
const htmlEscapes = { | ||
"&": "&", | ||
"<": "<", | ||
">": ">", | ||
'"': """, | ||
"'": "'", | ||
}; | ||
|
||
const regExp = /["&'<>]/g; | ||
|
||
const escaper = (match: string) => { | ||
return htmlEscapes[match as CHARACTERS_TO_ESCAPE]; | ||
}; | ||
|
||
type CHARACTERS_TO_ESCAPE = keyof typeof htmlEscapes; | ||
|
||
/** | ||
* Converts the characters "&", "<", ">", '"', "'" to their corresponding HTML entities. | ||
*/ | ||
export function escapeHtml(html: string) { | ||
return html.replaceAll(regExp, escaper); | ||
} |
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 @@ | ||
export * from "./debounce.js"; | ||
export * from "./escape-html.js"; | ||
export * from "./throttle.js"; | ||
export * from "./uniq-by.js"; |
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,13 @@ | ||
export function throttle<T extends (...arguments_: any[]) => void>( | ||
function_: T, | ||
timeFrame: number, | ||
): (...arguments_: Parameters<T>) => void { | ||
let lastTime = 0; | ||
return (...arguments_) => { | ||
const now = Date.now(); | ||
if (now - lastTime >= timeFrame) { | ||
function_(...arguments_); | ||
lastTime = now; | ||
} | ||
}; | ||
} |
2 changes: 1 addition & 1 deletion
2
...onsole/packages/uniq-by/src/index.test.ts → ...le/packages/utilities/src/uniq-by.test.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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.