Skip to main content

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

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

example/main.dart

// Copyright 2025 Mattia Pispisa
// SPDX-License-Identifier: MIT

// A copy of a recipe, written by `melos run recipes_sync`.
// Edit the recipe, then run it again:
// packages/_internal/crdt_lf_recipes/lib/hive_note/main.dart

import 'dart:io';

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

/// Adds a line to the stored note, and returns the whole note.
Future<String> addLine() async {
  final backend = await CRDTHive.open();

  // Reads the stored note (or starts an empty one), then writes every edit.
  final note = await backend.openDocument('note');
  final text = CRDTFugueTextHandler(note.document, 'body');

  text.insert(text.value.runes.length, 'Hello 🌍\n');
  final value = text.value;

  await note.persistence.dispose(); // writes what is still waiting
  note.document.dispose();
  await note.persistence.storage.close();
  await backend.close();

  return value;
}

Future<void> main() async {
  // Once per process, before the first open.
  Hive.init('note_db');
  CRDTHive.initialize();

  // One more line on every run.
  stdout.writeln(await addLine());
}
0
likes
160
points
171
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