The Elements of UI Engineering
On the principle that you can solve every problem in computer science by adding a layer of indirection, we solved all the problems listed in that Dan Abramov article by adding a few layers of indirection.<p>You didn’t write a fetch ever, you subscribed to a data feed from the data feed repository.<p>To prevent redundant fetches, the data feed was served by a cache, which then filled cache entries by doing the fetch.<p>Doing a POST invalidated the whole cache.<p>Which triggered fetches of everything, but only once/API.
The fetch return pushed out to all the subscribers.
The subscription was driven by the JSX, so only visible items had active subscriptions. Essentially, you wrapped your UI with the fetcher component, during your JSX display tree into a data dependency tree.<p>Optimizing the cache invalidation was a problem we ignored for later, because the fetch overhead wasn’t too bad, and we went from doing 40 fetches/page without the cache layer to 10, so the back end never noticed.