removeEntityOptimistically method
Remove an entity optimistically and return everything needed to roll back.
Implementation
EntityRemovalSnapshot removeEntityOptimistically(String type, String id) {
return _write(() {
final indexes = <String, int>{};
for (final entry in _lists.entries) {
final knownType = _listTypes[entry.key];
if (knownType != null && knownType != type) continue;
final index = entry.value.ids.indexOf(id);
if (index >= 0) indexes[entry.key] = index;
}
final snapshot = EntityRemovalSnapshot(
type: type,
id: id,
entity: readCanonicalEntity(type, id),
patch: readEntityPatch(type, id),
state: _entityStates[_ek(type, id)],
syncMetadata: _syncMetadata[_ek(type, id)],
listIndexes: Map.unmodifiable(indexes),
);
removeEntity(type, id);
return snapshot;
});
}