SyncHelper class

A reusable helper to manage partial patch diffs, debouncing, retries, and flushing per-id.

Usage:

  • Provide how to fetch a model's sync map by id (toSyncMapForId)
  • Optionally provide a sanitizer to strip local-only fields
  • Optionally handle onAckSuccess to update local state (e.g., clear update flags)

Constructors

SyncHelper({required dynamic realm, required Socket socket, required String userId, required String collectionName, required Map<String, dynamic>? toSyncMapForId(String id), Map<String, dynamic> sanitize(Map<String, dynamic>)?, void onAckSuccess(String id)?, void onNoDiff(String id)?, Map<String, dynamic> emitPreProcessor(Map<String, dynamic> rawJson)?, Duration debounceDelay = const Duration(milliseconds: 250), bool enableBatching = true, Duration batchWindow = const Duration(milliseconds: 300)})

Properties

batchWindow Duration
final
collectionName String
final
debounceDelay Duration
final
emitPreProcessor Map<String, dynamic> Function(Map<String, dynamic> rawJson)?
final
enableBatching bool
final
hashCode int
The hash code for this object.
no setterinherited
mongoOperations MongoOperations
getter/setter pair
onAckSuccess → void Function(String id)?
final
onNoDiff → void Function(String id)?
final
realm → dynamic
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sanitize Map<String, dynamic> Function(Map<String, dynamic>)
final
socket → Socket
final
toSyncMapForId Map<String, dynamic>? Function(String id)
final
userId String
final

Methods

cancelForId(String id) → void
cleanupOutbox() Future<void>
Cleanup expired or over-attempted outbox entries TTL: 48 hours, Max attempts: 100
computeAndScheduleDiff(String id, String collectionName) → void
Compute diff vs baseline and schedule if non-empty. If empty, calls onNoDiff.
dispose() → void
flushAllOutboxes() Future<void>
flushAllPending() Future<void>
initOutbox() Future<void>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
scheduleDelete(String id) → void
Schedule a deletion for the given entity id. This will take precedence over any pending patches for the same id and will be persisted in outbox.
scheduleFullSync(String id) → void
schedulePatch(String id, Map<String, dynamic> patch) → void
Directly schedule an arbitrary patch for the given entity id. This bypasses diffing and writes to the outbox immediately (debounced before network send). Safe to call repeatedly; patches will be merged and deduped.
setBaselineFromModel(String id) → void
setEmptyBaseline(String id) → void
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited