There I was... in day two of performance improvements for a tree control in React. (React wasn't the culprit). This particular control does some processing on the incoming data and builds an internal structure and it was that processing that was taking too long.
I had already reduced the runtime from "I don't know... it crashes Chrome" to about 30 seconds. Infinitely better but still not even in the ballpark of acceptible. but at least at that point I could get something -- anything -- out of the Performance profiler in Dev Tools. With the help of the profiler, I had made a few more adjustments and had the runtime down to ~12 - 14 seconds.
Today, however, the profiler led me to something unexpected.
Most developers agree that automated software testing is an important practice. It proves that code is correct now and that it stays correct in the future as the code evolves. However, despite this widely-held opinion, there are still lots of developers who aren't testing their software.
Not knowing what nor how to test are big barriers to getting started -- and that's just with regular code. The barrier feels even bigger for redux-saga code because generator functions can't be tested in the same way as regular functions.
This could become a big problem for teams who are increasingly relying on putting complex business logic in sagas without tests.
I am going to walk you through some saga unit tests written using a library called redux-saga-test-plan.
We wrote some sagas in the previous article (Part 4) for a mock RPG. Now let's test them!
React is pretty awesome, am I right?
Even if you've been struggling a bit. You believe deep down that it could be awesome... it will be awesome once you've mastered it.
And there are so many great resources out there. Places like Codecademy and freeCodeCamp are two very popular free resources for beginners. Who doesn't love free stuff? But you're not a beginner anymore.
You've been working with React for months... a year... two years, even. You know you're good at React... but you want to be great. If only you could get there.
Here's the burning question: how is a mid-level React developer supposed to level up when it's so difficult to find intermediate and advanced resources? Mostly you keep finding content written for complete newbies.
Well first of all, you might like to familiarize yourself with Mark Erikson's react-redux-links. He's a maintainer of Redux and has painstakingly curated years of content. But be warned, there is a lot of content. It's ideal for self-directed learners who know what they're looking. Otherwise, it can be quite overwhelming.
Here are some less-intimidating suggestions for leveling up your skills. Some are specific to React and others are general web development skills. Of course, to master React you're going to have to be well-rounded in all things web.
Does your web app use Redux-Saga and the Fetch API to make a lot of repeated or lengthy calls to a particular server?
You've probably noticed that Chrome limits concurrent connections to any given host.
This can be a big problem if one part of your app ends up blocking another part due to pending API requests.
Obviously, you should try to reduce the number of calls you make, where possible. Consolidating requests and using debounce or throttle techniques can help sometimes.
But sometimes you don't control the server or requirements dictate that you need to make those API calls regardless. Sometimes you're at the mercy of a slow database, slow network connection, or an impatient user.
I'm going to show you how you can "fire and forget" all your API calls through Redux-Saga with true request cancellation built into the system via the AbortController API.