Skip to content

Commit

Permalink
fix: getResult should match the tanstack version (#90)
Browse files Browse the repository at this point in the history
* fix: `getResult` should match the tanstack version

fixes #88

---------

Co-authored-by: kalijonn <[email protected]>
  • Loading branch information
peterferguson and kalijonn authored Aug 13, 2024
1 parent 4bd5475 commit 94fe5b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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

0 comments on commit 94fe5b4

Please sign in to comment.