Skip to content

Commit

Permalink
feat!: remove deprecated createDataType and displayObjectSize
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Sep 15, 2024
1 parent 5ed7245 commit 2923478
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 206 deletions.
6 changes: 0 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ const JsonViewerInner: FC<JsonViewerProps> = (props) => {
}

export const JsonViewer = function JsonViewer<Value> (props: JsonViewerProps<Value>): ReactElement {
if (process.env.NODE_ENV !== 'production') {
if ('displayObjectSize' in props) {
console.error('`displayObjectSize` is deprecated. Use `displaySize` instead.\nSee https://viewer.textea.io/migration/migration-v3#raname-displayobjectsize-to-displaysize for more information.')
}
}
const isAutoDarkTheme = useThemeDetector()
const themeType = useMemo(() => props.theme === 'auto'
? (isAutoDarkTheme ? 'dark' : 'light')
Expand Down Expand Up @@ -195,7 +190,6 @@ export * from './type'
export type { PathValueCustomGetter } from './utils'
export {
applyValue,
createDataType,
defineDataType,
deleteValue,
getPathValue,
Expand Down
79 changes: 0 additions & 79 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,85 +109,6 @@ export function deleteValue (input: any, path: (string | number)[], value: any)
return input
}

/**
* @deprecated use `defineDataType` instead
*/
// case 1: you only render with a single component
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Component: ComponentType<DataItemProps<ValueType>>
): {
is: (value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
// case 2: you only render with a single component with editor
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Component: ComponentType<DataItemProps<ValueType>>,
Editor: ComponentType<EditorProps<ValueType>>
): {
is: (value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<ValueType>>
Editor: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
// case 3: you only render with a component with pre and post.
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Component: ComponentType<DataItemProps<ValueType>>,
Editor: undefined,
PreComponent: ComponentType<DataItemProps<ValueType>>,
PostComponent: ComponentType<DataItemProps<ValueType>>
): {
is: (value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<ValueType>>
PreComponent: ComponentType<DataItemProps<ValueType>>
PostComponent: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
// case 4: need all of these
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Component: ComponentType<DataItemProps<ValueType>>,
Editor: ComponentType<EditorProps<ValueType>>,
PreComponent: ComponentType<DataItemProps<ValueType>>,
PostComponent: ComponentType<DataItemProps<ValueType>>
): {
is: (value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<ValueType>>
Editor: ComponentType<DataItemProps<ValueType>>
PreComponent: ComponentType<DataItemProps<ValueType>>
PostComponent: ComponentType<DataItemProps<ValueType>>
}
/**
* @deprecated use `defineDataType` instead
*/
export function createDataType<ValueType = unknown> (
is: (value: unknown, path: Path) => boolean,
Component: ComponentType<DataItemProps<ValueType>>,
Editor?: ComponentType<EditorProps<ValueType>> | undefined,
PreComponent?: ComponentType<DataItemProps<ValueType>> | undefined,
PostComponent?: ComponentType<DataItemProps<ValueType>> | undefined
): any {
if (process.env.NODE_ENV !== 'production') {
console.warn('createDataType is deprecated, please use `defineDataType` instead. See https://viewer.textea.io/migration/migration-v3#use-definedatatype-instead-of-createdatatype for more information.')
}
return {
is,
Component,
Editor,
PreComponent,
PostComponent
}
}

/**
* Define custom data types for any data structure
*/
Expand Down
122 changes: 1 addition & 121 deletions tests/util.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { expectTypeOf } from 'expect-type'
import type { ComponentType } from 'react'
import { describe, expect, test } from 'vitest'

import type { DataItemProps, Path } from '../src'
import { applyValue, createDataType, deleteValue, isCycleReference } from '../src'
import { applyValue, deleteValue, isCycleReference } from '../src'
import { getPathValue, pathValueDefaultGetter, safeStringify, segmentArray } from '../src/utils'

describe('function applyValue', () => {
Expand Down Expand Up @@ -212,123 +209,6 @@ describe('function isCycleReference', () => {
})
})

describe('function createDataType', () => {
test('case 1', () => {
const dataType = createDataType<string>(
(value) => {
expectTypeOf(value).toBeUnknown()
return true
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
}
)
expectTypeOf(dataType).toEqualTypeOf<{
is:(value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<string>>
}>()
expectTypeOf(dataType.is).returns.toBeBoolean()
expect(dataType.is).toBeTypeOf('function')
expect(dataType.Component).toBeTypeOf('function')
})
test('case 2', () => {
const dataType = createDataType<string>(
(value) => {
expectTypeOf(value).toBeUnknown()
return true
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
}
)
expectTypeOf(dataType).toEqualTypeOf<{
is:(value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<string>>
Editor: ComponentType<DataItemProps<string>>
}>()
expectTypeOf(dataType.is).returns.toBeBoolean()
expect(dataType.is).toBeTypeOf('function')
expect(dataType.Component).toBeTypeOf('function')
expect(dataType.Editor).toBeTypeOf('function')
})
test('case 3', () => {
const dataType = createDataType<string>(
(value) => {
expectTypeOf(value).toBeUnknown()
return true
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
},
undefined,
(props) => {
expectTypeOf(props.value).toBeString()
return null
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
}
)
expectTypeOf(dataType).toEqualTypeOf<{
is:(value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<string>>
PreComponent: ComponentType<DataItemProps<string>>
PostComponent: ComponentType<DataItemProps<string>>
}>()
expectTypeOf(dataType.is).returns.toBeBoolean()
expect(dataType.is).toBeTypeOf('function')
expect(dataType.Component).toBeTypeOf('function')
expect(dataType.PreComponent).toBeTypeOf('function')
expect(dataType.PostComponent).toBeTypeOf('function')
})

test('case 4', () => {
const dataType = createDataType<string>(
(value) => {
expectTypeOf(value).toBeUnknown()
return true
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
},
(props) => {
expectTypeOf(props.value).toBeString()
return null
}
)
expectTypeOf(dataType).toEqualTypeOf<{
is:(value: unknown, path: Path) => boolean
Component: ComponentType<DataItemProps<string>>
Editor: ComponentType<DataItemProps<string>>
PreComponent: ComponentType<DataItemProps<string>>
PostComponent: ComponentType<DataItemProps<string>>
}>()
expectTypeOf(dataType.is).returns.toBeBoolean()
expect(dataType.is).toBeTypeOf('function')
expect(dataType.Component).toBeTypeOf('function')
expect(dataType.Editor).toBeTypeOf('function')
expect(dataType.PreComponent).toBeTypeOf('function')
expect(dataType.PostComponent).toBeTypeOf('function')
})
})

describe('function segmentArray', () => {
test('case 1', () => {
const array = [1, 2, 3, 4, 5]
Expand Down

0 comments on commit 2923478

Please sign in to comment.