| ... | @@ -87,6 +87,7 @@ const mutDeleteItem = mutations.define({ | ... | @@ -87,6 +87,7 @@ const mutDeleteItem = mutations.define({ |
| 87 | // `optimistic` is provided a `helpers` object which implement automatic rollbacks. | 87 | // `optimistic` is provided a `helpers` object which implement automatic rollbacks. |
| 88 | optimistic({ client, get, helpers, args: [id], onSuccess, onRestore, onRefetch }) { | 88 | optimistic({ client, get, helpers, args: [id], onSuccess, onRestore, onRefetch }) { |
| 89 | // Remove the items matching the filter, but restore and refetch them on failure. | 89 | // Remove the items matching the filter, but restore and refetch them on failure. |
| | 90 | // On success, the default behavior is to also re-fetch queries. |
| 90 | helpers.arrayRemove(queryItemList, (item) => item === id); | 91 | helpers.arrayRemove(queryItemList, (item) => item === id); |
| 91 | // Set a property on an object, also restores and refetches. The `obj` | 92 | // Set a property on an object, also restores and refetches. The `obj` |
| 92 | // helpers implement a type-safe object path system for nested fields. | 93 | // helpers implement a type-safe object path system for nested fields. |
| ... | @@ -115,8 +116,8 @@ const mutDeleteItem = mutations.define({ | ... | @@ -115,8 +116,8 @@ const mutDeleteItem = mutations.define({ |
| 115 | // Example: `Successfully {description}` | 116 | // Example: `Successfully {description}` |
| 116 | describeResult: ({ get, args: [id] }) => "Deleted Item", | 117 | describeResult: ({ get, args: [id] }) => "Deleted Item", |
| 117 | | 118 | |
| 118 | // Since the optimistic handler is perfect, there is no need to refetch any | 119 | // Since this optimistic handler above is perfect, we can decide to disable |
| 119 | // data once a success case is hit. This defaults to false for simplicity. | 120 | // success-based refetching. This is default so that more things just work. |
| 120 | refetchOnSuccess: false, | 121 | refetchOnSuccess: false, |
| 121 | }); | 122 | }); |
| 122 | | 123 | |