4 ms·
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 ar
by obastard 8y ago
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.
You didn’t write a fetch ever, you subscribed to a data feed from the data feed repository.
To prevent redundant fetches, the data feed was served by a cache, which then filled cache entries by doing the fetch.
Doing a POST invalidated the whole cache.
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.
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.