upsertLocalDoc method

  1. @protected
T upsertLocalDoc({
  1. required String id,
  2. required UpsertDocDef<T> doc,
  3. 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 upsert
  • doc - The definition of how to upsert the document
  • doNotifyListeners - 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;
}