Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
Code Mirror 6 & React component on update re-subscribe after CM6 state reset

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda