y-crdt / y-octo

CRDT implementation which is compatible with https://github.com/yjs/yjs
https://octobase.pro/
Other
187 stars 5 forks source link

add sub doc callback api #18

Open darkskygit opened 1 year ago

darkskygit commented 1 year ago

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: