-
-
Notifications
You must be signed in to change notification settings - Fork 18
add serviceEffects and change serviceConstants semantic (fixes #634) #659
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 48df8f4 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 |
@@ -1842,6 +1842,24 @@ export const serviceFunctions = <I, S>( | |||
/** @internal */ | |||
export const serviceConstants = <I, S>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we simplify this to:
/**
* @since 1.0.0
* @category context
*/
export const serviceConstants: <I, S>(tag: Context.Tag<I, S>) => { [K in keyof S]: Effect<I, never, S[K]> } =
effect.serviceConstants
Then we won't need to add the same function to the other ecosystem packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, serviceFunctions
could be:
/**
* @since 1.0.0
* @category context
*/
export const serviceFunctions: <I, S>(
tag: Context.Tag<I, S>
) => {
[K in { [K in keyof S]: S[K] extends (...args: Array<any>) => any ? K : never }[keyof S]]: [S[K]] extends
[(...args: infer Args) => infer R]
? R extends Effect<infer R, infer E, infer A> ? (...args: Args) => Effect<I | R, E, A>
: (...args: Args) => Effect<I, never, R>
: never
} = effect.serviceFunctions
Which would also support non-effect returning functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't merge the two because we can't distinguish () => any
with () => Effect
, we'd need to check the return type and always flatten when it's an effect but that would end up flattening also the case where for example the return value is an option or an effect that shouldn't be flattened
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remember that implementation wise, we can't know the nature of the returning type at value level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example the return value is an option or an effect that shouldn't be flattened
I think this is already an issue due to the type augmentation.
But it does introduce an expectation gap, so yes I think we should not do it. Just make the constants change.
I had a go at the implementation here: 5da6a97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ofc core.isEffect ;)
Not really if we keep the functions and effect returning functions
separated
…On Fri, 15 Sept 2023, 17:10 Tim, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/internal/effect.ts
<#659 (comment)>:
> @@ -1842,6 +1842,24 @@ export const serviceFunctions = <I, S>(
/** @internal */
export const serviceConstants = <I, S>(
for example the return value is an option or an effect that shouldn't be
flattened
I think this is already an issue due to the type augmentation.
—
Reply to this email directly, view it on GitHub
<#659 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFZAKCTB4LATB32A6LGOCKDX2RVWTANCNFSM6AAAAAA4QJ3CRA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
No description provided.