Skip to content

Commit 5fe6188

Browse files
committed
Move initial values from Provider to default atom
1 parent 2ae8628 commit 5fe6188

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/state.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { atom } from 'jotai'
22

3+
import { lightColorspace } from './theme/base16'
34
import type { JsonViewerState, TypeRegistryState } from './type'
45

56
export const valueAtom = atom<JsonViewerState['value'] | undefined>(undefined)
@@ -14,14 +15,14 @@ export const rootNameAtom = atom<JsonViewerState['rootName'] | undefined>(undefi
1415
export const displayDataTypesAtom = atom<JsonViewerState['displayDataTypes'] | undefined>(undefined)
1516
export const displayObjectSizeAtom = atom<JsonViewerState['displayObjectSize'] | undefined>(undefined)
1617
export const onCopyAtom = atom<JsonViewerState['onCopy'] | undefined>(undefined)
17-
export const colorspaceAtom = atom<JsonViewerState['colorspace'] | undefined>(undefined)
18+
export const colorspaceAtom = atom<JsonViewerState['colorspace']>(lightColorspace)
1819
export const collapseStringsAfterLengthAtom = atom<JsonViewerState['collapseStringsAfterLength'] | undefined>(undefined)
1920
export const defaultInspectDepthAtom = atom<JsonViewerState['defaultInspectDepth'] | undefined>(undefined)
2021
export const objectSortKeysAtom = atom<JsonViewerState['objectSortKeys'] | undefined>(undefined)
2122
export const quotesOnKeysAtom = atom<JsonViewerState['quotesOnKeys'] | undefined>(undefined)
22-
export const inspectCacheAtom = atom<JsonViewerState['inspectCache'] | undefined>(undefined)
23-
export const hoverPathAtom = atom<JsonViewerState['hoverPath'] | undefined>(undefined)
24-
export const registryAtom = atom<TypeRegistryState['registry'] | undefined>(undefined)
23+
export const inspectCacheAtom = atom<JsonViewerState['inspectCache'] | undefined>({})
24+
export const hoverPathAtom = atom<JsonViewerState['hoverPath'] | null>(null)
25+
export const registryAtom = atom<TypeRegistryState['registry']>([])
2526

2627
export const getInspectCacheAtom = atom(
2728
(get) => get(inspectCacheAtom),

src/stores/JsonViewerStore.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@ import type { SetStateAction } from 'react'
44
import type { JsonViewerProps, Path } from '..'
55
import {
66
collapseStringsAfterLengthAtom,
7-
colorspaceAtom,
87
defaultInspectDepthAtom,
98
displayDataTypesAtom,
109
displayObjectSizeAtom,
1110
editableAtom,
1211
enableClipboardAtom,
1312
groupArraysAfterLengthAtom,
14-
hoverPathAtom,
1513
indentWidthAtom,
16-
inspectCacheAtom,
1714
keyRendererAtom,
1815
maxDisplayLengthAtom,
1916
objectSortKeysAtom,
2017
onChangeAtom,
2118
onCopyAtom,
2219
quotesOnKeysAtom,
23-
registryAtom,
2420
rootNameAtom,
2521
valueAtom
2622
} from '../state'
27-
import { lightColorspace } from '../theme/base16'
2823
import type { JsonViewerKeyRenderer, JsonViewerState } from '../type'
2924

3025
export { Provider as JsonViewerProvider } from 'jotai'
@@ -59,11 +54,7 @@ export const createJsonViewerStore = <T = unknown> (props: JsonViewerProps<T>):
5954
[quotesOnKeysAtom, props.quotesOnKeys ?? true],
6055
[displayDataTypesAtom, props.displayDataTypes ?? true],
6156
// internal state
62-
[inspectCacheAtom, {}],
63-
[hoverPathAtom, null],
64-
[colorspaceAtom, lightColorspace],
6557
[valueAtom, props.value],
66-
[displayObjectSizeAtom, props.displayObjectSize ?? true],
67-
[registryAtom, []] // moved from JsonViewerProvider
58+
[displayObjectSizeAtom, props.displayObjectSize ?? true]
6859
]
6960
export type JsonViewerStore = ReturnType<typeof createJsonViewerStore>

0 commit comments

Comments
 (0)