y_crdt 0.0.1 copy "y_crdt: ^0.0.1" to clipboard
y_crdt: ^0.0.1 copied to clipboard

y.js (https://github.com/yjs/yjs) Dart port, a CRDT implementation. CRDTs allow for local, offline editing and synchronization of shared data.

example/y_crdt_example.dart

import 'package:y_crdt/wit_world.dart';
import 'package:wasm_wit_component/wasm_wit_component.dart';

Future<void> main() async {
  final world = await createYCrdt(
    wasiConfig: WasiConfig(preopenedDirs: [], webBrowserFileSystem: {}),
    imports: YCrdtWorldImports(
      eventCallback: ({required event, required functionId}) {},
      eventDeepCallback: ({required event, required functionId}) {},
      undoEventCallback: ({required event, required functionId}) {},
    ),
  );

  final doc = world.yDocMethods.yDocNew();
  final docFinalizer = Finalizer<int>(
    (p0) => world.yDocMethods.yDocDispose(ref: YDoc.fromJson([p0])),
  );
  docFinalizer.attach(doc, doc.ref);

  final text = world.yDocMethods.yDocText(ref: doc, name: 'name');
  final length = world.yDocMethods.yTextLength(ref: text);
  assert(length == 0);

  world.yDocMethods.yTextPush(ref: text, chunk: 'hello');
  assert(world.yDocMethods.yTextToString(ref: text) == 'hello');
}
1
likes
150
pub points
42%
popularity

Publisher

unverified uploader

y.js (https://github.com/yjs/yjs) Dart port, a CRDT implementation. CRDTs allow for local, offline editing and synchronization of shared data.

Repository (GitHub)
View/report issues

Topics

#wasm #wit #crdt #offline #peer-to-peer

Documentation

API reference

License

MIT (LICENSE)

Dependencies

wasm_run, wasm_wit_component

More

Packages that depend on y_crdt