Optimistic Update with Rollback
Is this a good candidate for aquire release ? Assuming that if the request fail I want to rollback the local optimistic changes:
function likePhoto(photo: Photo) {
likedPhotos.update((liked) => {
liked.add(photo.id);
return liked;
});
const run = likePhotoRequest(photo.id).pipe(
Effect.tap(() =>
photos.update((oldPhotos) =>
oldPhotos.map((p) => {
if (p.id === photo.id) {
return { ...p, likes: p.likes + 1 };
}
return p;
}),
),
),
notifyError("Error liking photo"),
);
Effect.runPromise(run);
}