I currently have an object structured in the following way:
const obj: SomeType = {
images: {imageOrder1: imageLink, imageOrder2: imageLink},
imageOrder: [imageOrder1, imageOrder2]
}
The task at hand is to update each image within the obj.images
array (uploading it to a designated location) and then return the entire obj
as an observable. My current approach involves the following code snippet:
defer(() => of(obj)).pipe(
map(objs => obj.imageOrder),
switchMap(imageOrder => from(imageOrder)),
concatMap(order => {
const image = imageUrls[order];
return [order, uploadImage(image)];
}),
toArray(),
map(uploadResult => {
const [view, imageUploadResult] = uploadResult;
// Need to generate an updated object with new links
})
);
This process should ultimately yield the following result:
obj: Observable<obj> = {
images: {imageOrder1: updatedImage, imageOrder2: updatedImage},
imageOrder: [imageOrder1, imageOrder2]
}
What would be the most effective way to achieve this outcome?