Skip to content

Commit 5b49946

Browse files
KarthikMAMmanueliglesias
authored andcommitted
fix(offline-helpers): Preserve order of elements in update cache operation type (#325)
1 parent 082afec commit 5b49946

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/aws-appsync/src/helpers/offline.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ export const getUpdater = <T>(opType: CacheOperationTypes, idField = 'id'): (arr
152152

153153
switch (opType) {
154154
case CacheOperationTypes.ADD:
155-
case CacheOperationTypes.UPDATE:
156155
updater = (arr, newItem) => !newItem ? [...arr] : [...arr.filter(item => item[idField] !== newItem[idField]), newItem];
157156
break;
157+
case CacheOperationTypes.UPDATE:
158+
updater = (arr, newItem) => !newItem ? [...arr] : arr.map(item => item[idField] === newItem[idField] ? newItem : item);
159+
break;
158160
case CacheOperationTypes.REMOVE:
159161
updater = (arr, newItem) => !newItem ? [] : arr.filter(item => item[idField] !== newItem[idField]);
160162
break;

0 commit comments

Comments
 (0)