0.1.5 • Published 1 year ago

@netless/y v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@netless/y

Glue between netless app and CRDT libraries

import { createVector } from "@netless/y";
// var App = { kind, setup(context) {
const vector = createVector(context, "namespace");
vector.forEach((update) => CRDT.applyUpdate(update));
CRDT.on("update", (update) => vector.push(update));
vector.on("update", (update) => CRDT.applyUpdate(update));

See src/yjs.ts for a more real-life use case.

Structure

Vector

Think of it as a growing array, you can push CRDT operations into it.

type Value = any; // any JSON-serializable value

class Vector {
  readonly size: number;
  forEach(callback: (update: Value, index: number) => void): void;
  push(update: Value): void;
  swap(updates: Value[]): void;
  on(event: "update", callback: (update: Value) => void): void;
}

License

MIT @ netless