Remove deepmerge dependency, use merge and patch from rok
This commit is contained in:
parent
55da8880eb
commit
254919a6e3
4 changed files with 20 additions and 7 deletions
|
@ -55,7 +55,7 @@
|
|||
"react-dom": "^17.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"deepmerge": "^4.2.2",
|
||||
"react-use-gesture": "^9.1.3"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitHead": "55da8880eb3d8ab5fb62b5eb7853065922c95dcf"
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* --------------------- Primary -------------------- */
|
||||
|
||||
export type Patch<T> = Partial<{ [P in keyof T]: T | Partial<T> | Patch<T[P]> }>
|
||||
|
||||
export interface TLPage<T extends TLShape, B extends TLBinding> {
|
||||
id: string
|
||||
name?: string
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable no-redeclare */
|
||||
import type React from 'react'
|
||||
import deepmerge from 'deepmerge'
|
||||
import { TLBezierCurveSegment, TLBounds, TLBoundsCorner, TLBoundsEdge } from '../types'
|
||||
import vec from './vec'
|
||||
import './polyfills'
|
||||
import type { Patch } from '+index'
|
||||
|
||||
export class Utils {
|
||||
/* -------------------------------------------------- */
|
||||
|
@ -20,8 +20,18 @@ export class Utils {
|
|||
return Object.fromEntries((Object.entries(obj) as Entry<T>[]).filter(fn)) as Partial<T>
|
||||
}
|
||||
|
||||
static deepMerge<T>(target: T, source: any): T {
|
||||
return deepmerge(target, source, { arrayMerge: (a, b) => b, clone: false })
|
||||
static deepMerge = <T>(target: T, patch: Patch<T>): T => {
|
||||
const result: T = { ...target }
|
||||
|
||||
const entries = Object.entries(patch) as [keyof T, T[keyof T]][]
|
||||
|
||||
for (const [key, value] of entries)
|
||||
result[key] =
|
||||
value === Object(value) && !Array.isArray(value)
|
||||
? this.deepMerge(result[key], value)
|
||||
: value
|
||||
|
||||
return result
|
||||
|
||||
// const result = {} as T
|
||||
|
||||
|
|
|
@ -68,5 +68,6 @@
|
|||
"perfect-freehand": "^0.5.3",
|
||||
"react-hotkeys-hook": "^3.4.0",
|
||||
"rko": "^0.5.23"
|
||||
}
|
||||
},
|
||||
"gitHead": "55da8880eb3d8ab5fb62b5eb7853065922c95dcf"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue