Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!