Skip to content

Commit

Permalink
Merge pull request #33 from johanobergman/fix/update-when-removing-items
Browse files Browse the repository at this point in the history
Fix getQueriesToUpdate when mutation has fewer array items than the cached data
  • Loading branch information
klis87 authored Nov 30, 2024
2 parents 48cebd5 + 8e6a829 commit 74193ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions packages/normy/src/create-normalizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,29 @@ describe('createNormalizer', () => {
]);
});

it('returns query if mutation array and query array are of different length', () => {
const normalizer = createNormalizer();
normalizer.setQuery('query', {
id: '1',
list: [1, 2],
});

expect(
normalizer.getQueriesToUpdate({
id: '1',
list: [1],
}),
).toEqual([
{
queryKey: 'query',
data: {
id: '1',
list: [1],
},
},
]);
});

it('works with equal date objects', () => {
const normalizer = createNormalizer();

Expand Down
4 changes: 2 additions & 2 deletions packages/normy/src/create-normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const isMutationObjectDifferent = (
normalizedData: Data,
): boolean => {
if (Array.isArray(mutationData) && Array.isArray(normalizedData)) {
if (mutationData.length === 0) {
return normalizedData.length !== 0;
if (mutationData.length !== normalizedData.length) {
return true;
}

return mutationData.some((v, i) =>
Expand Down

0 comments on commit 74193ab

Please sign in to comment.