Skip to content

Commit

Permalink
Use lodash merge instead
Browse files Browse the repository at this point in the history
  • Loading branch information
cte committed Mar 2, 2025
1 parent f50e9a6 commit 618bf97
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
10 changes: 9 additions & 1 deletion webview-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webview-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"debounce": "^2.1.1",
"fast-deep-equal": "^3.1.3",
"fzf": "^0.5.2",
"lodash": "^4.17.21",
"lucide-react": "^0.475.0",
"mermaid": "^11.4.1",
"react": "^18.3.1",
Expand Down Expand Up @@ -61,6 +62,7 @@
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^14.6.1",
"@types/jest": "^27.5.2",
"@types/lodash": "^4.17.16",
"@types/node": "^18.0.0",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
Expand Down
29 changes: 4 additions & 25 deletions webview-ui/src/context/ExtensionStateContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { createContext, useCallback, useContext, useEffect, useState } from "react"
import { useEvent } from "react-use"
import { merge } from "lodash"

import { ApiConfigMeta, ExtensionMessage, ExtensionState } from "../../../src/shared/ExtensionMessage"
import { ApiConfiguration } from "../../../src/shared/api"
import { vscode } from "../utils/vscode"
Expand Down Expand Up @@ -252,28 +254,5 @@ export const useExtensionState = () => {
return context
}

export const mergeExtensionState = (prevState: ExtensionState, newState: ExtensionState) => {
const {
apiConfiguration: prevApiConfiguration,
customModePrompts: prevCustomModePrompts,
customSupportPrompts: prevCustomSupportPrompts,
experiments: prevExperiments,
...prevRest
} = prevState

const {
apiConfiguration: newApiConfiguration,
customModePrompts: newCustomModePrompts,
customSupportPrompts: newCustomSupportPrompts,
experiments: newExperiments,
...newRest
} = newState

const apiConfiguration = { ...prevApiConfiguration, ...newApiConfiguration }
const customModePrompts = { ...prevCustomModePrompts, ...newCustomModePrompts }
const customSupportPrompts = { ...prevCustomSupportPrompts, ...newCustomSupportPrompts }
const experiments = { ...prevExperiments, ...newExperiments }
const rest = { ...prevRest, ...newRest }

return { ...rest, apiConfiguration, customModePrompts, customSupportPrompts, experiments }
}
export const mergeExtensionState = (prevState: ExtensionState, newState: ExtensionState): ExtensionState =>
merge(prevState, newState)

0 comments on commit 618bf97

Please sign in to comment.