Skip to content

Commit

Permalink
Fix format again
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Dec 10, 2024
1 parent 4d8a50f commit d0636a3
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions examples/write-patterns/patterns/3-shared-persistent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,27 @@ export default function SharedPersistent() {
// Get the local optimistic state.
const localWrites = useSnapshot<Map<string, LocalWrite>>(optimisticState)

const computeOptimisticState = (synced: Todo[], writes: LocalWrite[]): Todo[] => {
return writes.reduce((synced: Todo[], { operation, value }: LocalWrite): Todo[] => {
switch (operation) {
case 'insert':
return [...synced, value as Todo]
case 'update':
return synced.map((todo) =>
todo.id === value.id ? { ...todo, ...value } : todo
)
case 'delete':
return synced.filter((todo) => todo.id !== value.id)
default:
return synced
}
}, synced)
const computeOptimisticState = (
synced: Todo[],
writes: LocalWrite[]
): Todo[] => {
return writes.reduce(
(synced: Todo[], { operation, value }: LocalWrite): Todo[] => {
switch (operation) {
case 'insert':
return [...synced, value as Todo]
case 'update':
return synced.map((todo) =>
todo.id === value.id ? { ...todo, ...value } : todo
)
case 'delete':
return synced.filter((todo) => todo.id !== value.id)
default:
return synced
}
},
synced
)
}

const todos = computeOptimisticState(sorted, [...localWrites.values()])
Expand Down

0 comments on commit d0636a3

Please sign in to comment.