Global Key-Value Store.beta

Co-Document

gokv allows for real-time syncing of documents, making it a powerful tool for building collaborative applications.

When a document is synced, it becomes a Proxy object that can be manipulated like a standard JavaScript object. Any updates made to the object are automatically saved and broadcasted to other sessions in real-time."

Example

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

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

// Sync the document, changes will be broadcasted to other sessions and saved automatically.
const obj = await doc.sync({ initial: { foo: "bar" } });

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

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

// Get the document snapshot
snapshot(obj); // { foo: "baz" }