upsertLocalDocs method
List<T>
upsertLocalDocs({
- required List<
String> ids, - required UpsertDocDef<
T> doc, - 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 upsertdoc
- The definition of how to upsert the documentsdoNotifyListeners
- 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;
}