YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.
https://syncedstore.org
MIT License
1.71k stars 51 forks source link

hocuspocus.dev usage example #36

Closed floer32 closed 2 years ago

floer32 commented 2 years ago

Do you know of a usage example of using SyncedStore with hocuspocus.dev as the server?

YousefED commented 2 years ago

Hi and welcome @hangtwenty !

This should be similar to how other providers work, as described at https://syncedstore.org/docs/sync-providers.

I haven't tried this yet, but when setting up the store, try this:

import { syncedStore, getYjsValue } from "@syncedstore/core";

export const store = syncedStore({ arrayData: [] });

const doc = getYjsValue(store);

const provider = new HocuspocusProvider({
  url: 'ws://127.0.0.1:1234',
  name: 'example-document',
  document: doc,
  onAwarenessUpdate: ({ states }) => {
    currentStates = states
  },
})

Feel free to reopen if you have additional questions! Looking forward to hearing your experience with syncedstore :)