createFetcher from @dan_abramov's talk is this thing:
We're calling it simple-cache-provider (for now). It's a basic cache that works for 80% of use cases, and (when it's done) will serve as a reference implementation for Apollo, Relay, etc.
https://github.com/facebook/react/blob/master/packages/simple-cache-provider/README.md …
-
Show this thread
-
Here's how suspending works: - in the render method, read a value from the cache. - if the value is already cached, the render continues like normal - if the value is not already cached, the cache *throws a promise* - when the promise resolves, React retries where it left off
15 replies 69 retweets 282 likesShow this thread -
Suspending is built on the mechanism as error boundaries. In fact, we recently (like last week) completely rewrote error handling to prepare for this feature. It's also built on the same "expiration time" model we use for CPU scheduling. I love it when features compose together!
8 replies 13 retweets 92 likesShow this thread -
Andrew Clark Retweeted Sebastian Markbåge
The promise throwing aspect is what
@sebmarkbage was referring to in this tweet. That was a fun day! This was the last major piece of the puzzle that finally made us confident enough to start implementing it.https://twitter.com/sebmarkbage/status/941163837625057280 …Andrew Clark added,
3 replies 6 retweets 56 likesShow this thread -
Andrew Clark Retweeted Andrew Clark
Previously, other APIs we had considered included a new lifecycle method called `shouldComponentBlock`. But it turns out promises are perfect for our use case because they return a single value and are *idempotent.*https://twitter.com/acdlite/status/908912040151982080 …
Andrew Clark added,
2 replies 3 retweets 25 likesShow this thread -
Idempotence is an important part of how suspense is modeled. Even though you may trigger network requests from inside the render method, it's still considered "pure" because it of the cache: it always returns the same value a given input. Arbitrary side-effects are disallowed.
3 replies 13 retweets 53 likesShow this thread -
The cache is shared throughout the React tree using—wait for it—the new context API. It's almost as if we designed context with this use case in mind!
3 replies 5 retweets 50 likesShow this thread -
Fun fact: for over a year, when suspense was just a sparkle of an idea, we colloquially referred to the feature as "blockers." But "block" sounds like the entire thread is blocked, which isn't the case. "Suspend" is the more accurate term. And since we're all suckers for puns...
2 replies 0 retweets 31 likesShow this thread -
In retrospect, I'm surprised we didn't land on "suspend" sooner, since it's the term used for coroutines, and React *Fiber* is literally named for a coroutine primitive. Only occurred to me after seeing the term in a rando tweet. SEE, my Twitter addiction was good for something!
3 replies 0 retweets 56 likesShow this thread
Seb Insua Retweeted Sebastian Markbåge
Good thread. I remember when I first saw the 'throwing promise' technique, wondering why you would want to do that. Would be really awesome to hear a longer form rationale. I think this is when I first saw it in the wild:https://twitter.com/sebmarkbage/status/941214259505119232?s=21 …
Seb Insua added,
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.