removeOptimisticPatch method
Remove a given patch from the list
This will also remove all "nested" patches, such as $queryId.update
(see recordOptimisticTransaction)
This allows for hierarchical optimism that is automatically cleaned up without having to tightly couple optimistic changes
This is called on every network result as cleanup
Implementation
void removeOptimisticPatch(String removeId) {
final patchesToRemove = optimisticPatches
.where(
(patch) =>
patch.id == removeId || _parentPatchId(patch.id) == removeId,
)
.toList();
if (patchesToRemove.isEmpty) {
return;
}
// Only remove + mark broadcast requested if something was actually removed.
// This is to prevent unnecessary rebroadcasts
optimisticPatches.removeWhere(
(patch) => patchesToRemove.contains(patch),
);
broadcastRequested = true;
}