Coder Social home page Coder Social logo

3dteemu / crdt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cachapa/crdt

0.0 0.0 0.0 158 KB

Dart implementation of Conflict-free Replicated Data Types (CRDTs)

Home Page: https://pub.dev/packages/crdt

License: Apache License 2.0

Dart 100.00%

crdt's Introduction

Dart implementation of Conflict-free Replicated Data Types (CRDTs).

This project is heavily influenced by James Long's talk CRTDs for Mortals and includes a Dart-native implementation of Hybrid Local Clocks (HLC) based the paper Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases.

It has zero external dependencies, so it should run everywhere where Dart runs.

Usage

The Crdt class works as a layer on top of a map. The simplest way to experiment is to initialise it an empty map:

import 'package:crdt/crdt.dart';

void main() {
  var crdt = MapCrdt('node_id');

  // Insert a record
  crdt.put('a', 1);
  // Read the record
  print('Record: ${crdt.get('a')}');

  // Export the CRDT as Json
  final json = crdt.toJson();
  // Send to remote node
  final remoteJson = sendToRemote(json);
  // Merge remote CRDT with local
  crdt.mergeJson(remoteJson);
  // Verify updated record
  print('Record after merging: ${crdt.get('a')}');
}

// Mock sending the CRDT to a remote node and getting an updated one back
String sendToRemote(String json) {
  final hlc = Hlc.now('another_nodeId');
  return '{"a":{"hlc":"$hlc","value":2}}';
}

You'll probably want to implement some sort of persistent storage by subclassing the Crdt class. An example using Hive is provided in hive_crdt.

Example

A simple example is provided with this project, otherwise for a real-world application check the tudo to-do app: client & server.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Testing

dart test

JavaScript version:

dart test --platform node

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.