Skip to content

Simplify ifs #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/DataKeyPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ export const DataKeyPair: React.FC<DataKeyPairProps> = (props) => {
const editable = useMemo(() => {
if (storeEditable === false) {
return false
} else if (!propsEditable) {
}
if (!propsEditable) {
// props.editable is false which means we cannot provide the suitable way to edit it
return false
} else if (typeof storeEditable === 'function') {
}
if (typeof storeEditable === 'function') {
return !!storeEditable(path, value)
} else {
return propsEditable
}
return propsEditable
}, [path, propsEditable, storeEditable, value])
const [tempValue, setTempValue] = useState(value)
const depth = path.length
Expand Down
11 changes: 4 additions & 7 deletions src/components/DataTypes/Object.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,10 @@ export const ObjectType: React.FC<DataItemProps<object>> = (props) => {
// object
let entries: [key: string, value: unknown][] = Object.entries(value)
if (objectSortKeys) {
entries = entries.sort(([a], [b]) => {
if (objectSortKeys === true) {
return a.localeCompare(b)
} else {
return objectSortKeys(a, b)
}
})
entries = entries.sort(([a], [b]) => objectSortKeys === true
? a.localeCompare(b)
: objectSortKeys(a, b)
)
}
const elements = entries.slice(0, displayLength).map(([key, value]) => {
const path = [...props.path, key]
Expand Down
11 changes: 5 additions & 6 deletions src/stores/typeRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ export function matchTypeComponents<Value> (
}
}
}
if (potential === undefined && typeof value === 'object') {
return objectType as unknown as DataType<Value>
} else {
if (potential === undefined) {
throw new DevelopmentError('this is not possible')
if (potential === undefined) {
if (typeof value === 'object') {
return objectType as unknown as DataType<Value>
}
return potential
throw new DevelopmentError('this is not possible')
}
return potential
}

export function useTypeComponents (value: unknown) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ export const isCycleReference = (
while (currentRoot !== value || arr.length !== 0) {
if (typeof currentRoot !== 'object' || currentRoot === null) {
return false
} else if (Object.is(currentRoot, value)) {
}
if (Object.is(currentRoot, value)) {
return currentPath.reduce<string>((path, value, currentIndex) => {
if (typeof value === 'number') {
return path + `[${value}]`
} else {
return path + `${currentIndex === 0 ? '' : '.'}${value}`
}
return path + `${currentIndex === 0 ? '' : '.'}${value}`
}, '')
}
const target = arr.shift()!
Expand Down