upsertLocalDocs method

  1. @protected
List<T> upsertLocalDocs({
  1. required List<String> ids,
  2. required UpsertDocDef<T> doc,
  3. bool doNotifyListeners = true,
})

Upserts (updates or inserts) multiple documents in local state.

This method will either update existing documents or create new ones if they don't exist. The doc function receives each current document (or null if it doesn't exist) and should return the new document state.

Parameters:

  • ids - The IDs of the documents to upsert
  • doc - The definition of how to upsert the documents
  • doNotifyListeners - Whether to notify listeners of the changes

Returns the list of upserted documents

Implementation

@protected
List<T> upsertLocalDocs({
  required List<String> ids,
  required UpsertDocDef<T> doc,
  bool doNotifyListeners = true,
}) {
  log.debug('Upserting ${ids.length} local docs');
  final pDocs = <T>[];
  for (final id in ids) {
    final pDoc = upsertLocalDoc(
      id: id,
      doc: doc,
      doNotifyListeners: false,
    );
    pDocs.add(pDoc);
  }
  if (doNotifyListeners) docsPerIdInformer.rebuild();
  return pDocs;
}