Skip to content

Commit 9360403

Browse files
committed
Move initial values from Provider to default atom
1 parent 36fa7cd commit 9360403

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)
@@ -15,14 +16,14 @@ export const displayDataTypesAtom = atom<JsonViewerState['displayDataTypes'] | u
1516
export const displayObjectSizeAtom = atom<JsonViewerState['displayObjectSize'] | undefined>(undefined)
1617
export const onCopyAtom = atom<JsonViewerState['onCopy'] | undefined>(undefined)
1718
export const onSelectAtom = atom<JsonViewerState['onSelect'] | undefined>(undefined)
18-
export const colorspaceAtom = atom<JsonViewerState['colorspace'] | undefined>(undefined)
19+
export const colorspaceAtom = atom<JsonViewerState['colorspace']>(lightColorspace)
1920
export const collapseStringsAfterLengthAtom = atom<JsonViewerState['collapseStringsAfterLength'] | undefined>(undefined)
2021
export const defaultInspectDepthAtom = atom<JsonViewerState['defaultInspectDepth'] | undefined>(undefined)
2122
export const objectSortKeysAtom = atom<JsonViewerState['objectSortKeys'] | undefined>(undefined)
2223
export const quotesOnKeysAtom = atom<JsonViewerState['quotesOnKeys'] | undefined>(undefined)
23-
export const inspectCacheAtom = atom<JsonViewerState['inspectCache'] | undefined>(undefined)
24-
export const hoverPathAtom = atom<JsonViewerState['hoverPath'] | undefined>(undefined)
25-
export const registryAtom = atom<TypeRegistryState['registry'] | undefined>(undefined)
24+
export const inspectCacheAtom = atom<JsonViewerState['inspectCache'] | undefined>({})
25+
export const hoverPathAtom = atom<JsonViewerState['hoverPath'] | null>(null)
26+
export const registryAtom = atom<TypeRegistryState['registry']>([])
2627

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

src/stores/JsonViewerStore.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,23 @@ 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
onSelectAtom,
2320
quotesOnKeysAtom,
24-
registryAtom,
2521
rootNameAtom,
2622
valueAtom
2723
} from '../state'
28-
import { lightColorspace } from '../theme/base16'
2924
import type { JsonViewerKeyRenderer, JsonViewerState } from '../type'
3025

3126
export { Provider as JsonViewerProvider } from 'jotai'
@@ -61,11 +56,7 @@ export const createJsonViewerStore = <T = unknown> (props: JsonViewerProps<T>):
6156
[quotesOnKeysAtom, props.quotesOnKeys ?? true],
6257
[displayDataTypesAtom, props.displayDataTypes ?? true],
6358
// internal state
64-
[inspectCacheAtom, {}],
65-
[hoverPathAtom, null],
66-
[colorspaceAtom, lightColorspace],
6759
[valueAtom, props.value],
68-
[displayObjectSizeAtom, props.displayObjectSize ?? true],
69-
[registryAtom, []] // moved from JsonViewerProvider
60+
[displayObjectSizeAtom, props.displayObjectSize ?? true]
7061
]
7162
export type JsonViewerStore = ReturnType<typeof createJsonViewerStore>

0 commit comments

Comments
 (0)