Skip to content

Commit

Permalink
fix: convert item updates to immutable Map
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofmochi committed Aug 5, 2021
1 parent dbb822a commit 7d5ea53
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/ws/hooks/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* React effect hooks to subscribe to real-time updates and mutate query client
*/

import { List, Record } from 'immutable';
import { List, Map, Record } from 'immutable';
import { useEffect } from 'react';
import { QueryClient } from 'react-query';
import {
Expand Down Expand Up @@ -49,7 +49,7 @@ export const configureWsItemHooks = (
if (current?.get('id') === item.id) {
switch (event.op) {
case 'update': {
queryClient.setQueryData(itemKey, item);
queryClient.setQueryData(itemKey, Map(item));
break;
}
case 'delete': {
Expand Down Expand Up @@ -97,15 +97,15 @@ export const configureWsItemHooks = (
if (!current.find((i) => i.id === item.id)) {
mutation = current.push(item);
queryClient.setQueryData(parentChildrenKey, mutation);
queryClient.setQueryData(buildItemKey(item.id), item);
queryClient.setQueryData(buildItemKey(item.id), Map(item));
}
break;
}
case 'update': {
// replace value if it exists
mutation = current.map((i) => (i.id === item.id ? item : i));
queryClient.setQueryData(parentChildrenKey, mutation);
queryClient.setQueryData(buildItemKey(item.id), item);
queryClient.setQueryData(buildItemKey(item.id), Map(item));

break;
}
Expand Down Expand Up @@ -154,15 +154,15 @@ export const configureWsItemHooks = (
if (!current.find((i) => i.id === item.id)) {
mutation = current.push(item);
queryClient.setQueryData(OWN_ITEMS_KEY, mutation);
queryClient.setQueryData(buildItemKey(item.id), item);
queryClient.setQueryData(buildItemKey(item.id), Map(item));
}
break;
}
case 'update': {
// replace value if it exists
mutation = current.map((i) => (i.id === item.id ? item : i));
queryClient.setQueryData(OWN_ITEMS_KEY, mutation);
queryClient.setQueryData(buildItemKey(item.id), item);
queryClient.setQueryData(buildItemKey(item.id), Map(item));

break;
}
Expand Down Expand Up @@ -212,15 +212,15 @@ export const configureWsItemHooks = (
if (!current.find((i) => i.id === item.id)) {
mutation = current.push(item);
queryClient.setQueryData(SHARED_ITEMS_KEY, mutation);
queryClient.setQueryData(buildItemKey(item.id), item);
queryClient.setQueryData(buildItemKey(item.id), Map(item));
}
break;
}
case 'update': {
// replace value if it exists
mutation = current.map((i) => (i.id === item.id ? item : i));
queryClient.setQueryData(SHARED_ITEMS_KEY, mutation);
queryClient.setQueryData(buildItemKey(item.id), item);
queryClient.setQueryData(buildItemKey(item.id), Map(item));

break;
}
Expand Down

0 comments on commit 7d5ea53

Please sign in to comment.