Skip to content

Commit

Permalink
Follow coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
johanobergman committed Jan 7, 2025
1 parent 857d68f commit 2d517fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions packages/normy-react-query/src/create-query-normalizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,14 @@ describe('createQueryNormalizer', () => {
});

// Set isInvalidated on the query.
client.invalidateQueries({ queryKey: ['book'] });
await client.invalidateQueries({ queryKey: ['book'] });

let state1 = client.getQueryCache().find({ queryKey: ['book'] })?.state;
const state1 = client.getQueryCache().find({ queryKey: ['book'] })?.state;

let dataUpdatedAt1 = state1?.dataUpdatedAt;
let isInvalidated1 = state1?.isInvalidated;
let error1 = state1?.error;
let status1 = state1?.status;
const dataUpdatedAt1 = state1?.dataUpdatedAt;
const isInvalidated1 = state1?.isInvalidated;
const error1 = state1?.error;
const status1 = state1?.status;

await sleep(1);

Expand All @@ -561,12 +561,12 @@ describe('createQueryNormalizer', () => {
name: 'Name updated',
});

let state2 = client.getQueryCache().find({ queryKey: ['book'] })?.state;
const state2 = client.getQueryCache().find({ queryKey: ['book'] })?.state;

let dataUpdatedAt2 = state2?.dataUpdatedAt;
let isInvalidated2 = state2?.isInvalidated;
let error2 = state2?.error;
let status2 = state2?.status;
const dataUpdatedAt2 = state2?.dataUpdatedAt;
const isInvalidated2 = state2?.isInvalidated;
const error2 = state2?.error;
const status2 = state2?.status;

expect(dataUpdatedAt1).toEqual(dataUpdatedAt2);
expect(isInvalidated1).toEqual(isInvalidated2);
Expand Down
12 changes: 6 additions & 6 deletions packages/normy-react-query/src/create-query-normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ const updateQueriesFromMutationData = (
const queriesToUpdate = normalizer.getQueriesToUpdate(mutationData);

queriesToUpdate.forEach(query => {
let queryKey = JSON.parse(query.queryKey) as QueryKey;
let cachedQuery = queryClient.getQueryCache().find({ queryKey });
const queryKey = JSON.parse(query.queryKey) as QueryKey;
const cachedQuery = queryClient.getQueryCache().find({ queryKey });

// react-query resets some state when setQueryData() is called.
// We'll remember and reapply state that shouldn't
// be reset when a query is updated via Normy.

// dataUpdatedAt and isInvalidated determine if a query is stale or not,
// and we only want data updates from the network to change it.
let dataUpdatedAt = cachedQuery?.state.dataUpdatedAt;
let isInvalidated = cachedQuery?.state.isInvalidated;
let error = cachedQuery?.state.error;
let status = cachedQuery?.state.status;
const dataUpdatedAt = cachedQuery?.state.dataUpdatedAt;
const isInvalidated = cachedQuery?.state.isInvalidated;
const error = cachedQuery?.state.error;
const status = cachedQuery?.state.status;

queryClient.setQueryData(queryKey, () => query.data, {
updatedAt: dataUpdatedAt,
Expand Down

0 comments on commit 2d517fe

Please sign in to comment.