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,
}) {
  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;
}