Chore: Removed some unused code
This commit is contained in:
parent
6ebaad747d
commit
d9530ea14f
2 changed files with 0 additions and 125 deletions
|
@ -1,103 +0,0 @@
|
|||
import React from 'react'
|
||||
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
||||
|
||||
const simplyMergeCallbacks: Merger = (oldCallback, newCallback) => {
|
||||
if (!oldCallback) return newCallback
|
||||
return (...args: $IntentionalAny[]) => {
|
||||
oldCallback(...args)
|
||||
newCallback(...args)
|
||||
}
|
||||
}
|
||||
|
||||
function initializeMergers() {
|
||||
const mergables = [
|
||||
'onClick',
|
||||
'onContextMenu',
|
||||
'onDoubleClick',
|
||||
'onDrag',
|
||||
'onDragEnd',
|
||||
'onDragEnter',
|
||||
'onDragExit',
|
||||
'onDragLeave',
|
||||
'onDragOver',
|
||||
'onDragStart',
|
||||
'onDrop',
|
||||
'onMouseDown',
|
||||
'onMouseEnter',
|
||||
'onMouseLeave',
|
||||
'onMouseMove',
|
||||
'onMouseOut',
|
||||
'onMouseOver',
|
||||
'onMouseUp',
|
||||
]
|
||||
mergables.forEach((propKey) => {
|
||||
mergerByPropKey[propKey] = simplyMergeCallbacks
|
||||
})
|
||||
}
|
||||
|
||||
let mergersInitialised = false
|
||||
|
||||
type Callback = (...args: $IntentionalAny[]) => void
|
||||
|
||||
type Merger = (originalCb: undefined | Callback, newCb: Callback) => Callback
|
||||
|
||||
const mergerByPropKey: {[propKey: string]: Merger} = {
|
||||
ref(_, newRef: $IntentionalAny) {
|
||||
return newRef
|
||||
},
|
||||
}
|
||||
|
||||
function getMerger(propKey: string) {
|
||||
if (!mergersInitialised) {
|
||||
mergersInitialised = true
|
||||
initializeMergers()
|
||||
}
|
||||
return mergerByPropKey[propKey]
|
||||
}
|
||||
|
||||
type MergableProps = Pick<
|
||||
React.AllHTMLAttributes<$IntentionalAny>,
|
||||
| 'onClick'
|
||||
| 'onContextMenu'
|
||||
| 'onDoubleClick'
|
||||
| 'onDrag'
|
||||
| 'onDragEnd'
|
||||
| 'onDragEnter'
|
||||
| 'onDragExit'
|
||||
| 'onDragLeave'
|
||||
| 'onDragOver'
|
||||
| 'onDragStart'
|
||||
| 'onDrop'
|
||||
| 'onMouseDown'
|
||||
| 'onMouseEnter'
|
||||
| 'onMouseLeave'
|
||||
| 'onMouseMove'
|
||||
| 'onMouseOut'
|
||||
| 'onMouseOver'
|
||||
| 'onMouseUp'
|
||||
> & {
|
||||
ref: React.Ref<$IntentionalAny>
|
||||
}
|
||||
|
||||
const cloneElementAndMergeCallbacks = (
|
||||
node: React.ReactElement<$IntentionalAny>,
|
||||
additionalProps: Partial<MergableProps>,
|
||||
) => {
|
||||
const newProps: Partial<MergableProps> = {}
|
||||
const keys = Object.keys(additionalProps)
|
||||
|
||||
for (const key of keys) {
|
||||
const merger = getMerger(key)
|
||||
if (!merger) {
|
||||
throw new Error(`Cannot merge react prop '${key}'`)
|
||||
}
|
||||
;(newProps as $IntentionalAny)[key] = merger(
|
||||
node.props[key],
|
||||
(additionalProps as $IntentionalAny)[key],
|
||||
)
|
||||
}
|
||||
|
||||
return React.cloneElement(node, newProps)
|
||||
}
|
||||
|
||||
export default cloneElementAndMergeCallbacks
|
|
@ -1,22 +0,0 @@
|
|||
import logger from '@theatre/shared/logger'
|
||||
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
||||
import {useCallback, useEffect, useState} from 'react'
|
||||
|
||||
const EMPTY_ARRAY: $IntentionalAny[] = []
|
||||
|
||||
export function useUnmount(fn: () => void) {
|
||||
useEffect(() => fn, EMPTY_ARRAY)
|
||||
}
|
||||
|
||||
export function useForceUpdate(debugLabel?: string) {
|
||||
const [, setTick] = useState(0)
|
||||
|
||||
const update = useCallback(() => {
|
||||
if (process.env.NODE_ENV !== 'production' && debugLabel)
|
||||
logger.log(debugLabel, 'forceUpdate', {trace: new Error()})
|
||||
|
||||
setTick((tick) => tick + 1)
|
||||
}, [])
|
||||
|
||||
return update
|
||||
}
|
Loading…
Reference in a new issue