Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sub doc callback api #18

Open
darkskygit opened this issue Aug 31, 2023 · 0 comments
Open

add sub doc callback api #18

darkskygit opened this issue Aug 31, 2023 · 0 comments
Assignees

Comments

@darkskygit
Copy link
Collaborator

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 darkskygit self-assigned this Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant