Skip to content

Commit 88ec703

Browse files
committed
fix(data): fix for TS conflict handler issue: aws-amplify/amplify-js#11006
1 parent d0f02f2 commit 88ec703

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/fragments/lib/datastore/js/conflict.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@ Finally you can configure the number of records to sync as an upper bound on ite
66

77
The code below illustrates a conflict resolution handler for the `Post` model that retries a mutation with the same title, but the most recent remote data for all other fields. The conflict resolution handler discards conflicts for all other models (by returning the `DISCARD` symbol imported from `@aws-amplify/datastore`).
88

9+
<BlockSwitcher>
10+
<Block name="TypeScript">
11+
12+
```ts
13+
import {
14+
DISCARD,
15+
PersistentModelConstructor,
16+
} from "@aws-amplify/datastore";
17+
18+
DataStore.configure({
19+
errorHandler: (error) => {
20+
console.warn("Unrecoverable error", { error });
21+
},
22+
conflictHandler: async (data) => {
23+
// Example conflict handler
24+
if (data.modelConstructor as PersistentModelConstructor<Todo> === Todo) {
25+
const remoteModel = data.remoteModel as Todo;
26+
const localModel = data.localModel as Todo;
27+
28+
const newModel = Todo.copyOf(remoteModel, (d) => {
29+
d.name = localModel.name;
30+
});
31+
32+
return newModel;
33+
}
34+
35+
return DISCARD;
36+
},
37+
maxRecordsToSync: 30000,
38+
fullSyncInterval: 60, // minutes
39+
});
40+
```
41+
42+
</Block>
43+
<Block name="JavaScript">
44+
945
```js
1046
import { DISCARD } from "@aws-amplify/datastore";
1147

@@ -32,3 +68,6 @@ DataStore.configure({
3268
fullSyncInterval: 60, // minutes
3369
});
3470
```
71+
72+
</Block>
73+
</BlockSwitcher>

0 commit comments

Comments
 (0)