-
-
Notifications
You must be signed in to change notification settings - Fork 902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createResource support for array source shorthand (like on) #935
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Typing this is really hard, barring making the type more complicated and breaking backwards compatibility of the second generic, or doubling the number of overloads with a source (4 total to 6 total). See https://tsplay.dev/weXYBW. Edit: Overloading is fine, if this makes it in 1.5 (since resources are being changed then I assume?) I'll provide the types then. I'm going to make use of this comment to keep track of some other possible changes to the resource types in 1.5:
|
I'm still not keen on this as it feels unnecessary. And looking at it makes me wish I had simplified |
Yeah, fair enough. There's a question of whether you want arrays of signals to act like shorthand for a signal consistently across the interface, and you're leaning the other direction. FWIW, in addition to Another possibility would be to have an explicit higher-order helper function along these lines: function combine(...funcs) {
return funcs.map((func) => func());
} Then you could write One final idea is to enable calling
In the scenarios where I want to pass in multiple sources to a resource, I also want to immediately destructure the array, so this would be helpful in both the |
I'm going to close this one. It is more likely that createResource changes design than this. Adding more arguments to fetcher is not the direction I want to go especially considering things like |
As discussed on Discord, this adds the option for an Array-of-Signals source argument for
createResource
.createResource([signal1, signal2], ...)
is shorthand forcreateResource(() => [signal1(), signal2()], ...)
. This feels very similar toon
which accepts a single signal or an array of signals, and I've found myself desiring this when I want my resource to depend on multiple signals.One current behavior this forbids: currently you can pass an array as the first argument and it will be treated as a static (not-called) source.
I'm not sure I got the types right, as TypeScript seems to be complaining about the tests I wrote. So if this gets approved functionality-wise, I'll have to summon the TypeScript experts to fix it. But I figured I'd wait until it's decided to be worthwhile.
Note that this uses the
Array-of-initial-size optimization from #934. If #934 is rejected, I can remove the initial size.map