Skip to content

Commit

Permalink
Add initialValues to debugstore init
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisen committed Jun 27, 2021
1 parent 4d1706d commit 1931dbc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const createStoreForDevelopment = (
) => writeAtom(state, atom, update)
const debugStore = {
version: 0,
atoms: [] as Atom<unknown>[],
atoms: Array.from(initialValues ?? []).map(([a]) => a),
state,
listeners: new Set<() => void>(),
}
Expand Down
39 changes: 39 additions & 0 deletions tests/devtools/useAtomsSnapshot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,42 @@ it('should let you access atoms and their state', async () => {
await findByText('countAtom: 1')
await findByText('petAtom: cat')
})

it('should contain initial values', async () => {
const countAtom = atom(1)
countAtom.debugLabel = 'countAtom'
const petAtom = atom('cat')
petAtom.debugLabel = 'petAtom'

const Displayer: React.FC = () => {
useAtom(countAtom)
useAtom(petAtom)
return null
}

const SimpleDevtools: React.FC = () => {
const atoms = useAtomsSnapshot()

return (
<div>
{Array.from(atoms).map(([atom, atomValue]) => (
<p key={atom.debugLabel}>{`${atom.debugLabel}: ${atomValue}`}</p>
))}
</div>
)
}

const { findByText } = render(
<Provider
initialValues={[
[countAtom, 42],
[petAtom, 'dog'],
]}>
<Displayer />
<SimpleDevtools />
</Provider>
)

await findByText('countAtom: 42')
await findByText('petAtom: dog')
})

0 comments on commit 1931dbc

Please sign in to comment.