-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove merge-anything and implement it on our own
- Loading branch information
1 parent
332f62a
commit 99294d1
Showing
7 changed files
with
64 additions
and
22 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
File renamed without changes.
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,30 @@ | ||
import { deepMerge } from '../object' | ||
|
||
test('deepMerge', () => { | ||
let obj1 = { | ||
a: 1, | ||
b: { | ||
c: 2, | ||
d: 3, | ||
e: 4, | ||
}, | ||
array: [1, 2, 3], | ||
} | ||
let obj2 = { | ||
a: 2, | ||
b: { | ||
c: 2, | ||
d: 3, | ||
}, | ||
array: [4, 5], | ||
} | ||
expect(deepMerge(obj1, obj2)).toEqual({ | ||
a: 2, | ||
b: { | ||
c: 2, | ||
d: 3, | ||
e: 4, | ||
}, | ||
array: [4, 5], | ||
}) | ||
}) |
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,9 +1,35 @@ | ||
import { TextStyle, ViewStyle } from 'react-native' | ||
|
||
import { DeepPartial } from './utility-types' | ||
|
||
export function objHasContent(obj: ViewStyle | TextStyle): boolean { | ||
return !!Object.keys(obj).length | ||
} | ||
|
||
export function stringHasContent(string: string): boolean { | ||
return !!string.length | ||
} | ||
|
||
function isObject(item: any) { | ||
return item && typeof item === 'object' && !Array.isArray(item) | ||
} | ||
|
||
function keys<T extends object>(obj: T): Array<keyof T> { | ||
return Object.keys(obj) as any | ||
} | ||
|
||
export function deepMerge<T extends object>(target: T, source: DeepPartial<T>): T { | ||
const output: T = Object.assign({}, target) | ||
if (isObject(target) && isObject(source)) { | ||
keys(source).forEach((key) => { | ||
if (isObject(source[key])) { | ||
if (!(key in target)) Object.assign(output, { [key]: source[key] }) | ||
// @ts-ignore | ||
else output[key] = deepMerge(target[key], source[key]) | ||
} else { | ||
Object.assign(output, { [key]: source[key] }) | ||
} | ||
}) | ||
} | ||
return output | ||
} |
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 |
---|---|---|
|
@@ -7679,11 +7679,6 @@ is-weakref@^1.0.2: | |
dependencies: | ||
call-bind "^1.0.2" | ||
|
||
is-what@^4.1.8: | ||
version "4.1.8" | ||
resolved "https://registry.yarnpkg.com/is-what/-/is-what-4.1.8.tgz#0e2a8807fda30980ddb2571c79db3d209b14cbe4" | ||
integrity sha512-yq8gMao5upkPoGEU9LsB2P+K3Kt8Q3fQFCGyNCWOAnJAMzEXVV9drYb0TXr42TTliLLhKIBvulgAXgtLLnwzGA== | ||
|
||
is-whitespace-character@^1.0.0: | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/is-whitespace-character/-/is-whitespace-character-1.0.4.tgz#0858edd94a95594c7c9dd0b5c174ec6e45ee4aa7" | ||
|
@@ -8985,13 +8980,6 @@ meow@^7.0.1: | |
type-fest "^0.13.1" | ||
yargs-parser "^18.1.3" | ||
|
||
[email protected]: | ||
version "5.1.4" | ||
resolved "https://registry.yarnpkg.com/merge-anything/-/merge-anything-5.1.4.tgz#c63132bfa5a4eddeff6f8dfa0df9d930253c8dee" | ||
integrity sha512-7PWKwGOs5WWcpw+/OvbiFiAvEP6bv/QHiicigpqMGKIqPPAtGhBLR8LFJW+Zu6m9TXiR/a8+AiPlGG0ko1ruoQ== | ||
dependencies: | ||
is-what "^4.1.8" | ||
|
||
[email protected]: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" | ||
|