How to properly use y-codemirror.next for managing multiple collaborative documents

Hi. I’m trying to figure out how to manage multiple collaborative documents using y-codemirror.next. In this given example the main idea is built around the binding instance. We should destroy binding before switching to a new document. Unfortunately for y-codemirror.next we have no binding instance at all:
const state = EditorState.create({ doc: ytext.toString(), extensions: [ basicSetup, javascript(), yCollab(ytext, provider.awareness, { undoManager }) ] })

const view = new EditorView({ state, parent: /** @type {HTMLElement} */ (document.querySelector('#editor')) })
How can we implement this idea for y-codemirror.next?
I will be very grateful for the help.

It looks like the example you have put each of the documents (Y.Text) in a Y.Array. Then when you click on the new document you want to switch to, you can update the state of the Code Mirror. Something like:

 view.setState(
      EditorState.create({
        doc: source.toString(),
        extensions: [
          keymap.of([...yUndoManagerKeymap]),
          basicSetup,
          html(),
          yCollab(source),
          EditorView.lineWrapping,
        ],
      })

Or you could destroy the view with view.destroy() and then recreate it.

1 Like

@andheller Thank you so much!