YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.

Home Page:https://syncedstore.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sync multiple documents

robhicks opened this issue · comments

I'm investigating SyncedStore.

My use case is allowing users to select multiple documents (projects, i.e., JSON) they can edit. I want to each document synced separately using y-indexeddb (for now) and y-webrtc (goal).

My current approach is to create the store:

import { syncedStore } from '@syncedstore/core'
import { svelteSyncedStore } from '@syncedstore/svelte'

const projects = syncedStore({projects: []})
const store = svelteSyncedStore(projects)

export default store

And then, when the user inputs the id of the document in a form, attempting the following:

const createProject = () => {
    const doc = getYjsValue(store)
    new IndexeddbPersistence(projectId, doc);
    const project = {name, id: projectId, ...description && {description}}
    $store.projects.push(project)
    clear()
  }

Doing that creates a IndexedDB database named as the projectId, but causes the following console errors:

Uncaught TypeError: Cannot read properties of undefined (reading 'on')
    at new IndexeddbPersistence (y-indexeddb.js:113:9)
    at HTMLButtonElement.createProject (CreateProjectModal.svelte:27:41)

encoding.js:506 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'store')
    at writeStateAsUpdate (encoding.js:506:36)
    at encodeStateAsUpdateV2 (encoding.js:525:3)
    at encodeStateAsUpdate (encoding.js:556:71)
    at y-indexeddb.js:77:27

Can I do what I'm wanting to do with SyncedStore?