Omit thunk in class-based resources when not needed#1008
Conversation
|
|
🦋 Changeset detectedLatest commit: d656eb4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| */ | ||
| static from<SomeResource extends Resource<any>>( | ||
| this: Constructor<SomeResource>, | ||
| context: unknown |
There was a problem hiding this comment.
that overload makes the type tests fail.. ie, when this is a thunk, then the types are not checked against the args from signature. This needs to stay intact.
Also for me it is late in the eve right now and I will postpone this
There was a problem hiding this comment.
My alternative solution wasn't working either:
static from<SomeResource extends Resource<any>, CT = unknown>(
this: Constructor<SomeResource>,
contextOrThunk: CT extends Function ? AsThunk<ArgsFrom<SomeResource>> : unknown
): SomeResource;|
|
||
| declare const __ResourceArgs__: unique symbol; | ||
|
|
||
| type Context = object; |
There was a problem hiding this comment.
As an attempt to work with more specific types, we (Jan and me) tried to give the Context its own type. That is, we started with unknown but stopped with object, the reason is, that destroyable accepts an object at
Maybe Context can be such a type:
type Context = Exclude<object, Thunk>;| static from<SomeResource extends Resource<any>, _C extends Context>( | ||
| this: Constructor<SomeResource>, | ||
| contextOrThunk: _C extends Thunk ? AsThunk<ArgsFrom<SomeResource>> : _C | ||
| ): SomeResource; |
There was a problem hiding this comment.
As a result for Context being very broadly typed due to destroyable (linked above), this required a second generic parameter here to test against. Basically, the same condition used in the code:
but here on type-level.
There was a problem hiding this comment.
yeah, function vs object typings are hard :(
There was a problem hiding this comment.
thank a ton for such a thorough changelog entry!
|
|
||
| Omit thunk arg for class based resources when not needed | ||
|
|
||
| When using a `Resource` but not using arguments with reactive parameters, initializing them still required the usage of a thunk, ie: |
There was a problem hiding this comment.
| When using a `Resource` but not using arguments with reactive parameters, initializing them still required the usage of a thunk, ie: | |
| When using the class-based `Resource` without reactive parameters, initializing _used to_ require the usage of a thunk, ie: |
| } | ||
| ``` | ||
|
|
||
| ... for basically, no reason. This change makes thunks a non-required parameter, leading into cleaner code like so: |
There was a problem hiding this comment.
| ... for basically, no reason. This change makes thunks a non-required parameter, leading into cleaner code like so: | |
| This change makes thunks a non-required parameter, leading into cleaner code like so: |
When using a
Resourcebut not using arguments with reactive parameters, then initializing them, so far still required the usage of a thunk, ie:... for basically, no reason. This PR makes thunks a non-required parameter, leading into cleaner code like so:
:)