y-octo icon indicating copy to clipboard operation
y-octo copied to clipboard

add sub doc callback api

Open darkskygit opened this issue 2 years ago • 0 comments
trafficstars

In yjs, sub doc is loaded in the following way:

let doc = new Y.Doc()
console.log('init main doc');

doc.on('subdocs', ({ loaded }) => {
  loaded.forEach(subdoc => {
    console.log('init subdoc provider');
    new SomethingProvider(subdoc.guid, subdoc)
  })
})

let subDoc = doc.getMap("map").get("some_sub_doc")
subDoc.on('synced', () => {
  console.log('synced');
  // when doc synced by provider, we can get sub doc's data
})
console.log('loading');
subDoc.load()

// exec workflow:
// init main doc -> loading -> init subdoc provider -> synced

In y-octo, we have implemented the parsing of sub doc identifiers in ydoc, this means that to add subdoc support to y-octo, what we need to do is:

  • provide an API to allow doc to know its own synchronization status
  • provide an API, pass in a doc instance, and use external implementation to load the doc binary from anywhere and apply update
  • maintain a thread-safe weak reference to a subdoc instance inside doc

darkskygit avatar Aug 31 '23 04:08 darkskygit