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: getResult should match the tanstack version #90

Merged
merged 2 commits into from
Aug 13, 2024
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
25 changes: 18 additions & 7 deletions __tests__/atomWithMutationState_spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,26 @@ it('atomWithMutationState multiple', async () => {
() => client
)

const mutationStateAtom = atomWithMutationState(
const pendingMutationStateAtom = atomWithMutationState(
() => ({ filters: { mutationKey: ['test-atom'], status: 'pending' } }),
() => client
)

const allMutationStatesAtom = atomWithMutationState(
() => ({ filters: { mutationKey: ['test-atom'] } }),
() => client
)

function App() {
const [{ mutate: mutate1 }] = useAtom(mutateAtom1)
const [{ mutate: mutate2 }] = useAtom(mutateAtom2)
const [mutations] = useAtom(mutationStateAtom)
const [pendingMutationState] = useAtom(pendingMutationStateAtom)
const [allMutationStates] = useAtom(allMutationStatesAtom)

return (
<div>
<p>mutationCount: {mutations.length}</p>
<p>all: {allMutationStates.length}</p>
<p>pending: {pendingMutationState.length}</p>
<button
onClick={() => {
mutate1(1)
Expand All @@ -63,11 +70,15 @@ it('atomWithMutationState multiple', async () => {
</Provider>
)

await findByText('mutationCount: 0')
await findByText('all: 0')
await findByText('pending: 0')
fireEvent.click(getByText('mutate'))
await findByText('mutationCount: 2')
await findByText('all: 2')
await findByText('pending: 2')
resolve1?.()
await findByText('mutationCount: 1')
await findByText('all: 2')
await findByText('pending: 1')
resolve2?.()
await findByText('mutationCount: 0')
await findByText('all: 2')
await findByText('pending: 0')
})
2 changes: 1 addition & 1 deletion src/atomWithMutationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getResult<TResult = MutationState>(
options: MutationStateOptions<TResult>
): Array<TResult> {
return mutationCache
.findAll({ ...options.filters, status: 'pending' })
.findAll(options.filters)
.map(
(mutation): TResult =>
(options.select
Expand Down
Loading