Skip to content

Commit

Permalink
fix(offline-helpers): Preserve order of elements in update cache oper…
Browse files Browse the repository at this point in the history
…ation type (#325)
  • Loading branch information
KarthikMAM authored and manueliglesias committed Dec 30, 2018
1 parent 082afec commit 5b49946
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/aws-appsync/src/helpers/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ export const getUpdater = <T>(opType: CacheOperationTypes, idField = 'id'): (arr

switch (opType) {
case CacheOperationTypes.ADD:
case CacheOperationTypes.UPDATE:
updater = (arr, newItem) => !newItem ? [...arr] : [...arr.filter(item => item[idField] !== newItem[idField]), newItem];
break;
case CacheOperationTypes.UPDATE:
updater = (arr, newItem) => !newItem ? [...arr] : arr.map(item => item[idField] === newItem[idField] ? newItem : item);
break;
case CacheOperationTypes.REMOVE:
updater = (arr, newItem) => !newItem ? [] : arr.filter(item => item[idField] !== newItem[idField]);
break;
Expand Down

0 comments on commit 5b49946

Please sign in to comment.