Global Key-Value Store.beta

Co-Document

Co-Document syncs document in real-time, at edge.

A Co-document is a Proxy object, that means you can use it like a normal object. When you update the document object, the changes will be broadcasted to other sessions and saved automatically.

Example

import gokv, { subscribe } from "https://deno.land/x/gokv@0.0.23/mod.ts";

// Initialize a co-document, needs to specify an unique ID.
const doc = gokv.Document("DOC_ID", { initData: { foo: "bar" } });

// Sync the document, changes will be broadcasted to other sessions and saved automatically.
const obj = await doc.sync();

// Subscribe the document changes
subscribe(obj, () => {
  console.log(obj.foo); // "baz"
})

// Update the document
obj.foo = "baz";