crdt_lf_hive 0.5.0 copy "crdt_lf_hive: ^0.5.0" to clipboard
crdt_lf_hive: ^0.5.0 copied to clipboard

Hive adapters for CRDT LF library objects, providing persistence for Change and Snapshot objects.

example/main.dart

// The example prints its result, and it is not a library entry point.
// ignore_for_file: avoid_print

import 'package:crdt_lf/crdt_lf.dart';
import 'package:crdt_lf_hive/crdt_lf_hive.dart';
import 'package:hive/hive.dart';

Future<void> main() async {
  const itemsToAdd = 3;
  const dbLocation = './example/db';
  const documentId = '784ff372-6f0a-4fe9-8e63-19b72fd18c23';

  Hive.init(dbLocation);
  CRDTHive.initialize();

  final backend = await CRDTHive.open();

  // Reads the boxes into a document and follows it: everything written from
  // here on is stored without another line of code. The identity comes from
  // the backend too, so every run is the same author.
  final note = await backend.openDocument(documentId);
  final list = CRDTListHandler<String>(note.document, 'list');

  print('read back: ${list.value}');

  final length = list.value.length;
  for (var i = length; i < length + itemsToAdd; i++) {
    list.insert(i, 'Item $i');
  }

  // Writes what is still waiting. Without it the process could end before the
  // delayed write runs.
  await note.persistence.dispose();
  note.document.dispose();

  print('now: ${list.value}');
  print('documents in the database: ${(await backend.documentIds).length}');

  await backend.close();
  await CRDTHive.closeAllBoxes();
}
0
likes
160
points
227
downloads

Documentation

API reference

Publisher

verified publishermattiapispisa.it

Weekly Downloads

Hive adapters for CRDT LF library objects, providing persistence for Change and Snapshot objects.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#crdt #local-first #hive #persistence #dart

License

MIT (license)

Dependencies

crdt_lf, crdt_lf_persistence, hive, hlc_dart

More

Packages that depend on crdt_lf_hive