Merge pull request #140 from unix/test

test: remove unused default-values
This commit is contained in:
witt
2020-04-27 15:11:54 +08:00
committed by GitHub
8 changed files with 11 additions and 16 deletions

View File

@@ -4,14 +4,13 @@ import withDefaults from '../utils/with-defaults'
interface Props {
x: number
y: number
color?: string
onCompleted?: Function
onCompleted: () => void
color: string
}
const defaultProps = {
x: 0,
y: 0,
onCompleted: () => {},
}
export type ButtonDrip = Props & typeof defaultProps

View File

@@ -6,7 +6,7 @@ export interface FieldItem {
}
export interface FieldsetConfig {
register: (item: FieldItem) => void
register?: (item: FieldItem) => void
currentValue: string
inGroup: boolean
}
@@ -14,7 +14,6 @@ export interface FieldsetConfig {
const defaultContext = {
inGroup: false,
currentValue: '',
register: () => {},
}
export const FieldsetContext = React.createContext<FieldsetConfig>(defaultContext)

View File

@@ -25,18 +25,18 @@ const FieldsetGroup: React.FC<React.PropsWithChildren<FieldsetGroupProps>> = Rea
const [selfVal, setSelfVal] = useState<string>(value)
const [items, setItems, ref] = useCurrentState<FieldItem[]>([])
const register = useCallback((newItem: FieldItem) => {
const register = (newItem: FieldItem) => {
const hasItem = ref.current.find(item => item.value === newItem.value)
if (hasItem) {
useWarning('The "value" of each "Fieldset" must be unique.', 'Fieldset')
}
setItems([...ref.current, newItem])
}, [])
}
const providerValue = useMemo(() => ({
currentValue: selfVal,
inGroup: true,
register: () => register,
register,
}), [selfVal])
const clickHandle = useCallback((nextValue: string) => {

View File

@@ -47,8 +47,7 @@ const Fieldset: React.FC<React.PropsWithChildren<FieldsetProps>> = React.memo(({
}
useEffect(() => {
const r: any = register({ value, label })
r({ value, label })
register && register({ value, label })
}, [])
useEffect(() => {

View File

@@ -1,13 +1,12 @@
import React from 'react'
export interface TreeConfig {
onFileClick: (path: string) => void
onFileClick?: (path: string) => void
initialExpand: boolean
isImperative: boolean
}
const defaultContext = {
onFileClick: () => {},
initialExpand: false,
isImperative: false,
}

View File

@@ -31,7 +31,7 @@ const TreeFile: React.FC<React.PropsWithChildren<TreeFileProps>> = ({
const currentPath = useMemo(() => makeChildPath(name, parentPath), [])
const clickHandler = (event: React.MouseEvent) => {
stopPropagation(event)
onFileClick(currentPath)
onFileClick && onFileClick(currentPath)
}
return (

View File

@@ -31,7 +31,7 @@ const ModalAction: React.FC<ModalActionProps> = React.memo(({
const clickHandler = (event: MouseEvent<HTMLButtonElement>) => {
if (disabled) return
const actionEvent = Object.assign({}, event, {
close,
close: () => close && close(),
})
onClick && onClick(actionEvent)
}

View File

@@ -1,11 +1,10 @@
import React from 'react'
export interface ModalConfig {
close: () => void
close?: () => void
}
const defaultContext = {
close: () => {},
}
export const ModalContext = React.createContext<ModalConfig>(defaultContext)