[Miro-favorite-state-diagram](https://miro.com/app/board/uXjVMrLB_ms=/?share_link_id=480596830055)
BE: [1,2,3,4] -> start In memory BL
LL: [1,2,3,4] sync
Local Add case
LL:PLP [1,2,3,4,5,6] -> sync flag true - PLP leave -> put call
BL in memory [1,2,3,4]
Diff [5,6] -> put call -> BE synced and sync flag false
BE 3 add case and 2 delete
LL: [1,2,3,4] -> synced flag false
BE: [1,2,7,8,9]
Diff: [1,2,7,8,9] -> override app local
BE 3 add case and 2 delete, Local adds 1
LL: [1,2,3,4,10] -> synced true,
BE: [1,2,7,8,9]
Diff: [1,2,7,8,9] -> override app local
App -> added items array list and deleted items
BE-> Local updated with BE list
PLP/SRLP/PDP/Cart -> Favorite -> add to added item array // update local
SRLP -> x deleted -> add to deleted items -> update local
Sync flag true
=================================
App Start
BE list : [1,2,7,8,9] -> update local with this data LL
SRLP -> [1,2,7,8,9,3,4] add 3,4 -> diff [3,4] and put call to add it. on leave SRLP page
Needs Playground tested:
BE list : [1,2,7,8,9] -> update local with this data LL
SRLP -> [7,8,9,3,4] -> diff two time, substract BE set with Local and local set with BE, We need to find which result needs to delete and add. Unique set and substract with local and BE list which decides to delete and add result set.
====================================================
### Common Use cases to sync Favorites:
**Use Case #1**
* App Start
* Syncing -> BE list [1,2,3] and Local List: [1,2,3] -> No changes
* Should not have any Add/Delete calls
**Use Case #2**
* App Start
* Syncing -> BE list [1,2,3] and Local List: [1,2,3] -> No changes
* PLP/SRLP/Cart/PDP -> Local add items [1,2,3,4]
* Find diff of added items and make put call to add items on leaving page
**Use Case #3**
* App Start
* Syncing -> BE list [1,2,3] and Local List: [1,2,3] -> No changes
* PLP/SRLP/Cart/PDP -> Local add items 4 [1,2,3,4] + delete 2 = [1,3,4]
* Find diff of added items and make call to add and delete items on leaving page, in this case we have to make 2 calls, delete first and add.
**Use Case #4** (this does not make any sense)
* App Foreground
* Syncing -> BE list [1,2,3,4,5] adds 4,5 and Local List: [1,2,3] -> make unique list and save in local.
* PLP/SRLP/Cart/PDP -> Local add items 4 [1,2,3,4] + delete 2 = [1,3,4]
* Find diff of added items and make call to add and delete items on leaving page, in this case we have to make 2 calls, delete first and add.
**Use Case #5**
* App Foreground
* Syncing -> BE list [1,4,5] adds 4,5 and delete 2,3 and Local List: [1,2,3] -> Sync local list with BE list by sustacting deleted items.
* PLP/SRLP/Cart/PDP -> Local add items 4 [1,2,3,4] + delete 2 = [1,3,4]
* Find diff of added items and make call to add and delete items on leaving page, in this case we have to make 2 calls, delete first and add.
**Use Case #5**
* App Foreground/Start
* Syncing -> BE list is empty [] and Local List: [1,2,3] -> Sync local list with BE list and make put call if local has favorites items
* PLP/SRLP/Cart/PDP -> Local add items 4 [1,2,3,4] + delete 2 = [1,3,4]
* Find diff of added items and make call to add and delete items on leaving page, in this case we have to make 2 calls, delete first and add.
**Use Case #5**
* App Start/Foreground
* Syncing -> BE list is empty [] and Local List: [] -> No any calls
* PLP/SRLP/Cart/PDP -> Local add items 4 [1,2,3,4] + delete 2 = [1,3,4]
* Find diff of added items and make call to add and delete items on leaving page, in this case we have to make 2 calls, delete first and add.
**Use Case #6**
* App Start
* Syncing -> BE list [1,2,3] and Local List: [1,2,3] -> No changes
* PLP/SRLP/Cart/PDP -> Local delete all items [] = []
* Find diff of deleted items and make call delete items on leaving page, in this case we have to make only 1 call
**Use Case #7**
* App Start/Foreground
* Syncing -> BE list is empty [] and Local List: [] -> No any calls
* PLP/SRLP/Cart/PDP -> Local add items 4 [1,2,3,4] + delete all = []
* Find diff of added items and no any call because diff has no change
--------