How to update nodeview from outside

let nodeViews = [];

let editor = new EditorView( this._editor_show_el , {

    state: EditorState.create({
        doc: doc,
    }),

    nodeViews: {

        'mainbody'(node, view, getPos) {

            let obj = new MainbodyView(node, view, getPos, {
            });

            nodeViews.push(obj);

            return obj;
        }

    },

});


setTimeout(x => {

  console.log('nodeViews[0]', nodeViews[0]);
  // update it
  nodeViews[0].update_jsmind('ac');

}, 1000);

At present, I do like this, which can realize my needs, but if it is multi person real-time cooperation, it will not work well

1 Like

Node decorations can be used to pass information to node views (though those are also not the easiest thing to set up). I think there is a need for some imperative way to force node views to redraw, but I’m not sure what it would look like yet.

For you, would a view method that broadcasts a given object to all node views in the document (allowing them to run their own update logic, and possibly opt to be redrawn entirely through a return value) work?

2 Likes

Node decorations may not be enough

My requirement is that there is a Mind map component in nodeview, and the interface inside can be updated from the outside when multiple people collaborate in real time.

At present, it is achievable but not elegant

Demo video :

@marijin was such an imperative approach ever implemented? Right now we have to do weird things to update the NodeView like scan the document for the nodes that need updating and set a dummy attribute. It would be wonderful to have imperative updates.

No. Having node views that are stateful (beyond the node and decorations they get), is problematic in general—they may be redrawn and lose their state, when content around them changes.