Skip to content
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

fix(snapshot): Add initialValues to debugstore init #566

Merged
merged 1 commit into from
Jun 27, 2021
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
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')
})