Accessing other instance in WidgetType.updateDOM

When using CodeMirror within a frontend framework like Svelte, you probably also want to use the framework to implement the DOM for WidgetTypes, however WidgetType.updateDOM only gets a reference to the old DOM element, not to the old instance of the same class (that with e.g. Svelte would hold the component reference). As a workaround I can store the references in a map and attach ids to the wrapper DOM elements to enable the lookup of the component references in updateDOM but it would be convenient if CodeMirror just provided the old instance as a parameter.

That sounds like a good idea. This patch implements it:

1 Like

Awesome thanks! Works like a charm. Just sent a PR to slightly improve the type of the new parameter: Change WidgetType.updateDOM from type to this by not-my-profile · Pull Request #81 · codemirror/view · GitHub