Day 184: Refactoring Hell

A fun thought popped into my head earlier today: “Maybe migrating everything to Redux was a huge mistake.”

Not for technical reasons, mind you. I mean, I’ll still have to do a lot of work to make this setup performant and reliable, but this reason popped up for completely unrelated reason.

Morale.

It’s in the dumps.

Before I decided to dive into Redux, I was maybe a week away from sharing Browserflow with friends. (Or at least, it felt that way — chances are, I probably would’ve found some other fantastic reason why it’d make sense to delay it another week.) Now I’m in the middle of swapping out the patterns and architecture I’ve refined over the course of nearly a year of building five different browser extensions, and I foolishly did not consider how much of a drain it would be.

Of course, I made the decision expecting that the rational understanding of why it’d be beneficial to adopt Redux would help me power through, but it turns out that I have these mushy things called ~~feelings~~ and ~~motivation~~ that’s fueled by things other than cold hard analysis.

Things are breaking left and right!

Things that I’ve fixed long ago are breaking again!

I have zero tests! Of course!

Here’s an example of a moment from earlier today where I was feeling like there was no end in sight: I found that clicking “Stop” didn’t actually stop the flow, and I wanted to console.log it up so I can see what’s happening in my background script. The problem was that I hadn’t set up a way to persist and hydrate state yet, so that meant that every time I made a change to the background script, state would be wiped out. Which meant that I had to create the test flow over and over again.

So I realized I needed to figure out how to persist state so I’m not spending all my time just creating the test flow repeatedly, so I go find redux-persist and start reading the documentation on how to use it. Okay, so I need an adapter to have it persist to Chrome’s storage. Thankfully, someone had written one, but it’s in pure Javascript with no type definitions and it’s too obscure for anyone else to have written type definitions for it so VS Code puts that nasty red underline that I just can’t get past. Of course, I could just write an ambient declaration and get over myself, but the purist won’t have any of that.

So in order to investigate a bug with flows not stopping, I had to first write a storage adapter to use with redux-persist. You know what I did?

I played Counter-Strike instead.

When I decided to stop running from my problems and also stop being so unreasonable, I ended up doing things piecemeal (getting redux-persist working using localStorage instead of Chrome’s storage then fixing the “flows not stopping” bug, then writing the storage adapter) and things felt okay again.

And I’m starting to see the light at the end of the tunnel — there are only a few more pieces before the refactor is mostly done and I’ll have reached parity with what I had before. And then I could add the undo/redo feature that I was excited about!

I just need to make sure I don’t give up before that happens. The road to ramen continues.