I recently started playing with CM6 and got stuck at a react component which contains tabs each pointing to separate text/code. On tab click, I reset CM6 state. On the init of the component, I register an event listener via:
extensions.unshift(EditorView.updateListener.of(onUpdate))
Now after a user clicks on a different tab/file I reset the editor via:
view?.setState(
EditorState.create({
doc: resetValue,
selection,
extensions: [mySetup, EditorView.updateListener.of(onUpdate)],
}),
I reset since I do not want to mix the history between the different "files". After the reset, I can not get the onUpdate to fire with the proper context. It always points to the original. In other words, any values in the onUpdate definition outside of that handler are not current.
I am trying to understand how can I unregister the initial onUpdate and register it again in the extensions on reset? I tried something like this:
view?.dispatch({
effects: StateEffect.reconfigure.of([EditorView.updateListener.of(onUpdate)]),
});
Any help would be greatly appreciated.
The steps were correct.
view?.dispatch({
effects: StateEffect.reconfigure.of([EditorView.updateListener.of(<YOUR FN>)]),
});
Will take care of the re-subscription
The issue was a closure on one of my functions.