isar_sync 0.1.0-dev.3
isar_sync: ^0.1.0-dev.3 copied to clipboard
Offline-first, event-sourced sync for Isar apps: capture local changes and converge them across devices through pluggable cloud adapters (Drive, iCloud).
isar_sync examples #
Runnable snippets that show how to wire the core pipeline.
basic.dart— a minimal end-to-end cycle (capture → queue → push → pull → apply) against an in-memory demo adapter.isar_collection_mapping_template.dart— template for mapping Isar collections to aCollectionMappedSyncStore.
Run the basic example:
dart run example/basic.dart
Minimal usage #
import 'package:isar_sync/isar_sync.dart';
const deviceId = 'device-A';
final queue = InMemorySyncQueue();
final core = SyncCore(
queue: queue,
adapter: myAdapter, // GoogleDriveSyncAdapter or ICloudSyncAdapter
applyEngine: DefaultApplyEngine(
store: InMemorySyncStore(),
conflictResolver: const LastWriteWinsConflictResolver(),
localDeviceId: deviceId,
),
cursorStore: InMemorySyncCursorStore(),
);
final capture = QueueBackedChangeCapture(queue: queue, deviceId: deviceId);
await capture.capture(
SyncMutation(
collection: 'notes',
entityId: 'n1',
operation: SyncOperation.upsert,
payload: {
'title': 'hello',
'updatedAt': DateTime.now().toUtc().toIso8601String(),
},
),
);
final report = await core.syncOnce();
print('pushed=${report.pushedCount}, pulled=${report.pulledCount}');
See the package README and doc/usage.md for the full guide.