Add a store for values that may not be computed yet - #806
Conversation
✅ Deploy Preview for kitbag-router ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
e1f5d22 to
23c506b
Compare
A value becomes a promise the moment it is first asked for, so whoever needs it can await it without knowing when, or by whom, it will be computed. Values live in scopes that can be handed on or discarded together. Nothing uses it yet. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
stackoverfloweth
left a comment
There was a problem hiding this comment.
My only question is the value of having both a pending state and a running state. I see that something can "watch" for a value by being subscribed and that's meaningful for the store. I also see that when it's running it's actually trying to fulfill a promise that will update those who are watching. Is that basically it?
A Vs |
Description
First step of #805. Nothing uses this yet — the store is added on its own so it can be reviewed without the churn of rewiring props at the same time.
A value becomes a promise the moment it is first asked for, rather than only existing once its getter has run. Whoever needs it can await it without knowing when, or by whom, it will be computed:
Alongside the promise, each key records where it has got to — nothing has asked for it, something is waiting on it, its getter is in flight, or how that getter settled. Rendering reads that synchronously instead of waiting a tick, and a getter returning
undefinedor anErrorstays an ordinary value rather than being mistaken for "not ready" or "failed".A store is also the unit of lifetime. Disposing one rejects everything still outstanding, so anything waiting resumes rather than being suspended for the life of the page — which is what prefetching needs, since most prefetched work is for a navigation that never happens.