Refactoring a JavaScript class
This article was originally published on Rails Designer This article is taken from the book JavaScript for Rails Developers (use ONE-YEAR-OLD to get 25% discount 🥳). It is a book I published about...

Source: DEV Community
This article was originally published on Rails Designer This article is taken from the book JavaScript for Rails Developers (use ONE-YEAR-OLD to get 25% discount 🥳). It is a book I published about a year ago. Over that period, many hundreds bought the book. It is written for Ruby/Rails developers to make JavaScript your 2nd favourite language. I always get a little excited when I see a good refactoring happen. So I want to share this article; it is one of the last chapters where I go over an exisintg part of the code that is created in the book to refactor it with the goal to make it: more readable; easier to understand at a glance. This is the current code it started with: import { Annotation, Transaction } from "@codemirror/state" import { EditorView } from "codemirror" const editorCache = { pairs: new WeakMap(), store(sourceEditor, duplicateEditor) { this.pairs.set(sourceEditor, duplicateEditor) }, get(editor) { return this.pairs.get(editor) } } export const splitView = { for: (edi