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,
}) {
final pDoc = doc(_doc.value, turboVars(id: id));
log.debug('Upserting local doc with id: $id');
if (doNotifyListeners) {
beforeLocalNotifyUpdate?.call(pDoc);
}
_doc.update(pDoc, doNotifyListeners: doNotifyListeners);
if (doNotifyListeners) {
afterLocalNotifyUpdate?.call(pDoc);
}
return pDoc;
}