Created
September 5, 2020 09:37
-
-
Save Coly010/fff546b5d5ae061e6f0bee4a02e16b1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mappedInv$ = | |
| // Gets all docs | |
| this.invService.getAll().pipe( | |
| // Stream each element of the array | |
| mergeMap((inventory) => from(inventory)), | |
| // Using each element of the array, do your next action | |
| mergeMap((inventoryItem: InventoryItem) => | |
| // This use case involved getting more details from a difference collection | |
| this.itemService.getAsync(inventoryItem.itemId).pipe( | |
| take(1), | |
| map((item) => ({ ...inventoryItem, item } as InventoryItem)) | |
| ) | |
| ), | |
| // Collect all the results back into one array | |
| // Scan will collect over time, it may be worth using reduce() | |
| scan( | |
| (inventory: Inventory, inventoryItem) => | |
| inventory.find((i) => i.id === inventoryItem.id) | |
| ? inventory | |
| : [...inventory, inventoryItem], | |
| [] | |
| ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment