upsertLocalDoc method
T
upsertLocalDoc({
- required String id,
- required UpsertDocDef<
T> doc, - bool doNotifyListeners = true,
Upserts (updates or inserts) a document in local state.
This method will either update an existing document or create a new one
if it doesn't exist. The doc
function receives the current document
(or null if it doesn't exist) and should return the new document state.
Parameters:
id
- The ID of the document to upsertdoc
- The definition of how to upsert the documentdoNotifyListeners
- Whether to notify listeners of the change
Returns the upserted document
Implementation
@protected
T upsertLocalDoc({
required String id,
required UpsertDocDef<T> doc,
bool doNotifyListeners = true,
}) {
log.debug('Upserting local doc with id: $id');
final pDoc = doc(tryFindById(id), turboVars(id: id));
docsPerIdInformer.updateCurrent(
(value) => value..[pDoc.id] = pDoc,
doNotifyListeners: doNotifyListeners,
);
return pDoc;
}