You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Virtually all of my frontend projects need a primitive like the fully typed dependOn I propose below. In short, I usually need two or more async resources (say, network calls) to be available together for some UI element to be fully available, and those async resources will sometimes depend on each other, creating a dependency graph rooted in the final UI element:
graph TD;
A --> B;
B --> Final;
C --> Final;
D --> B;
D --> C;
Loading
Per Solid documentation, leaf nodes (A & D) are createResource(async fn)s with no source. But then, to create dependent resources (B, C & Final) which require inputs, I couldn't find a simple, don't-repeat-yourself "API" in standard Solid and ended up writing the dependOn helper below. Note how dependencies are cleanly passed once and are readily usable as same-name arguments in the fetcher.
const[A,{refetch: refetchA}]=createResource(fetchA);const[D]=createResource(fetchD);const[B]=createResource(...dependOn({ A, D },fetchB);const[C]=createResource(...dependOn({ D },fetchC);const[final]=createResource(...dependOn({ B, C },fetchFinal);asyncfunctionfetchB({ A, D }){returnA+D;}asyncfunctionfetchC({ D }){returnD*2;}asyncfunctionfetchFinal({ B, C }){returnB+C;}
That implementation is not perfect though. While error state is correctly handled, only the fully "ready" state is correctly propagated. The loading aspect is lost on resources with inputs. However what I want is to only trigger a redraw when one of the inputs changes. I don't want final to disappear while an input loads so as to create the last UI disruptions.
This seems like an extremely standard feature that should be built-in. What am I missing? Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks,
Virtually all of my frontend projects need a primitive like the fully typed
dependOn
I propose below. In short, I usually need two or more async resources (say, network calls) to be available together for some UI element to be fully available, and those async resources will sometimes depend on each other, creating a dependency graph rooted in the final UI element:Per Solid documentation, leaf nodes (A & D) are
createResource(async fn)
s with nosource
. But then, to create dependent resources (B, C & Final) which require inputs, I couldn't find a simple, don't-repeat-yourself "API" in standard Solid and ended up writing thedependOn
helper below. Note how dependencies are cleanly passed once and are readily usable as same-name arguments in the fetcher.The way it is used is the following (Solid Playground):
That implementation is not perfect though. While error state is correctly handled, only the fully "ready" state is correctly propagated. The loading aspect is lost on resources with inputs. However what I want is to only trigger a redraw when one of the inputs changes. I don't want
final
to disappear while an input loads so as to create the last UI disruptions.This seems like an extremely standard feature that should be built-in. What am I missing? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions