replaceEntityPatch method

void replaceEntityPatch(
  1. String type,
  2. String id,
  3. Map<String, Object?>? patch
)

Replace the exact local patch for one entity in a single publication.

This is used by conflict-safe DevTools preview restoration so returning to the prior patch cannot expose an intermediate cleared state.

Implementation

void replaceEntityPatch(String type, String id, Map<String, Object?>? patch) {
  _write(() {
    if (patch == null || patch.isEmpty) {
      final bucket = _patches[type];
      bucket?.remove(id);
      if (bucket != null && bucket.isEmpty) _patches.remove(type);
    } else {
      _patches.putIfAbsent(type, () => {});
      _patches[type]![id] = Map<String, Object?>.of(patch);
    }
    _notifyEntity(type, id);
  });
}