Skip to content

Commit

Permalink
fix: TET-245 deep clone default config (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
kudyniuk authored Sep 15, 2023
1 parent e9382f4 commit ac917ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"rfdc": "^1.3.0",
"styled-components": "5.3.3"
},
"devDependencies": {
Expand Down Expand Up @@ -79,4 +80,4 @@
"prettier --write"
]
}
}
}
11 changes: 10 additions & 1 deletion src/services/mergeConfigWithCustom/mergeConfigWithCutom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { memoize, merge } from 'lodash';
import rfdc from 'rfdc';

const clone = rfdc();

type Params<T, K> = {
defaultConfig: T;
Expand All @@ -10,8 +13,14 @@ const memoizedMerge = memoize(
(...args) => JSON.stringify(args[0]) + JSON.stringify(args[1]),
);

const copyMergeMemoize = <T, K>({ defaultConfig, custom }: Params<T, K>): T => {
const defaultConfigClone = clone(defaultConfig);

return memoizedMerge(defaultConfigClone, custom);
};

export const mergeConfigWithCustom = <T, K>({
defaultConfig,
custom,
}: Params<T, K>): T =>
custom ? memoizedMerge(defaultConfig, custom) : defaultConfig;
custom ? copyMergeMemoize({ defaultConfig, custom }) : defaultConfig;

0 comments on commit ac917ee

Please sign in to comment.