crdt_lf 0.1.0
crdt_lf: ^0.1.0 copied to clipboard
Conflict-free replicated data type (CRDT) - Local-first implementation provided in dart
CRDT LF #
A Conflict-free Replicated Data Type (CRDT) implementation in Dart. This library provides solutions for:
- Text Editing.
- List Editing.
- Text Editing with Fugue Algorithm (The Art of the Fugue: Minimizing Interleaving in Collaborative Text Editing" di Matthew Weidner e Martin Kleppmann).
Features #
- Hybrid Logical Clock: Uses HLC for causal ordering of operations
- Automatic Conflict Resolution: Automatically resolves conflicts in a CRDT
- Local Availability: Operations are available locally as soon as they are applied
Getting Started #
Add this to your package's pubspec.yaml
file:
dependencies:
crdt_lf: ^1.0.0
Usage #
Basic Usage #
import 'package:crdt_lf/crdt_lf.dart';
void main() {
// Create a new document
final doc = CRDTDocument(
peerId: PeerId.parse('45ee6b65-b393-40b7-9755-8b66dc7d0518'),
);
// Create a text handler
final text = CRDTFugueTextHandler(doc, 'text1');
// Insert text
text.insert(0, 'Hello');
// Delete text
text.delete(0, 2); // Deletes "He"
// Get current value
print(text.value); // Prints "llo"
}
Distributed Collaboration Example #
Architecture #
The library is built around several key components:
CRDTDocument #
The main document class that manages the CRDT state and handles synchronization between peers.
Handlers #
Handlers are the core components of the library. They manage the state of a specific type of data and provide operations to modify it.
CRDTFugueTextHandler
: Handles text editing with the Fugue algorithm.CRDTListHandler
: Handles list editing.CRDTTextHandler
: Handles text editing.
DAG #
A Directed Acyclic Graph that maintains the causal ordering of operations.
Change #
Represents a modification to the CRDT state, including operation ID, dependencies, and timestamp.
Frontiers #
A structure that manages the frontiers (latest operations) of the CRDT.
Project Status #
This library is currently in progress and under active development. While all existing functionality is thoroughly tested, we are continuously working on improvements and new features.
Roadmap #
Contributing #
We welcome contributions! Whether you want to:
- Fix bugs
- Add new features
- Improve documentation
- Optimize performance
- Or something else
Feel free to:
- Check out our GitHub repository
- Look at the open issues
- Submit a Pull Request