Remove deepmerge dependency, use merge and patch from rok

This commit is contained in:
Steve Ruiz 2021-09-06 14:09:15 +01:00
parent 55da8880eb
commit 254919a6e3
4 changed files with 20 additions and 7 deletions

View file

@ -55,7 +55,7 @@
"react-dom": "^17.0.2"
},
"dependencies": {
"deepmerge": "^4.2.2",
"react-use-gesture": "^9.1.3"
}
}
},
"gitHead": "55da8880eb3d8ab5fb62b5eb7853065922c95dcf"
}

View file

@ -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

View file

@ -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

View file

@ -68,5 +68,6 @@
"perfect-freehand": "^0.5.3",
"react-hotkeys-hook": "^3.4.0",
"rko": "^0.5.23"
}
},
"gitHead": "55da8880eb3d8ab5fb62b5eb7853065922c95dcf"
}