-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
396 additions
and
373 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test, describe } from "vitest"; | ||
|
||
import merge from "./merge"; | ||
|
||
describe(merge.name, () => { | ||
test("applies entries not in the source", ({ expect }) => { | ||
const merged = merge({ a: 1 }, { a: 2, b: 3, c: 4 }); | ||
console.log({ merged }); | ||
expect(merged).toStrictEqual({ | ||
a: 1, | ||
b: 3, | ||
c: 4 | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { deepmerge } from "deepmerge-ts"; | ||
import { defu, defuArrayFn } from 'defu'; | ||
|
||
import { logger } from '@storybook/core/client-logger'; | ||
|
||
export default <TObj = any>(a: TObj, b: Partial<TObj>) => { | ||
if (Array.isArray(a) && !Array.isArray(b)) { | ||
export default <TObj = any>(a: TObj, b: Partial<TObj> & any) => { | ||
if (Array.isArray(a)) { | ||
if (Array.isArray(b)) { | ||
return defuArrayFn(a, b); | ||
} | ||
|
||
logger.log(['the types mismatch, picking', a]); | ||
return a; | ||
} | ||
|
||
return deepmerge(a, b); | ||
// TODO: Ask for what is prefered: | ||
// 1. type guard (safe at runtime, but potential performance slow-down) | ||
// 2. or type assertion (unsafe at runtime) | ||
return defu(a as object, b); | ||
}; |
Oops, something went wrong.