diff --git a/packages/effect-fc/src/Form.ts b/packages/effect-fc/src/Form.ts index 16577e4..15ca682 100644 --- a/packages/effect-fc/src/Form.ts +++ b/packages/effect-fc/src/Form.ts @@ -63,16 +63,20 @@ export namespace make { readonly onSubmit: ( this: Form, NoInfer, NoInfer, unknown, unknown, unknown>, value: NoInfer, - ) => Effect.Effect + ) => Effect.Effect>> readonly initialSubmitProgress?: SP readonly autosubmit?: boolean readonly debounce?: Duration.DurationInput } + + export type Success = ( + Form | Result.Progress>, SP> + ) } export const make = Effect.fnUntraced(function* ( options: make.Options -): Effect.fn.Return> { +): Effect.fn.Return> { const valueRef = yield* SubscriptionRef.make(Option.none()) const errorRef = yield* SubscriptionRef.make(Option.none()) const validationFiberRef = yield* SubscriptionRef.make(Option.none>()) @@ -80,7 +84,7 @@ export const make = Effect.fnUntraced(function* ( ): Effect.Effect< Option.Option>, NoSuchElementException, - Scope.Scope | Result.forkEffectPubSub.OutputContext + Scope.Scope | SR > => Effect.whenEffect( self.valueRef.pipe( Effect.andThen(identity), @@ -185,11 +189,17 @@ export const submit = ( export namespace service { export interface Options extends make.Options {} + + export type Return = Effect.Effect< + Form | Result.Progress>, SP>, + never, + Scope.Scope | R | Exclude | Result.Progress> + > } export const service = ( options: service.Options -): Effect.Effect, never, Scope.Scope | R | SR> => Effect.tap( +): service.Return => Effect.tap( make(options), form => Effect.forkScoped(run(form)), ) diff --git a/packages/effect-fc/src/Result.ts b/packages/effect-fc/src/Result.ts index 07b9e32..23318f8 100644 --- a/packages/effect-fc/src/Result.ts +++ b/packages/effect-fc/src/Result.ts @@ -186,7 +186,7 @@ export const makeProgressLayer = (): Layer.Layer< })) -export namespace forkEffect { +export namespace forkEffectSubscriptionRef { export type InputContext = R extends Progress ? [X] extends [P] ? R : never : R export type OutputContext = Scope.Scope | Exclude | Progress> @@ -195,13 +195,13 @@ export namespace forkEffect { } } -export const forkEffect = ( - effect: Effect.Effect>>, - options?: forkEffect.Options

, +export const forkEffectSubscriptionRef = ( + effect: Effect.Effect>>, + options?: forkEffectSubscriptionRef.Options

, ): Effect.Effect< Subscribable.Subscribable>, never, - forkEffect.OutputContext + forkEffectSubscriptionRef.OutputContext > => Effect.tap( SubscriptionRef.make>(initial()), ref => Effect.forkScoped(State().pipe( @@ -220,9 +220,12 @@ export const forkEffect = ( ) as Effect.Effect>, never, Scope.Scope> export namespace forkEffectPubSub { - export type InputContext = forkEffect.InputContext - export type OutputContext = forkEffect.OutputContext - export interface Options

extends forkEffect.Options

{} + export type InputContext = R extends Progress ? [X] extends [P] ? R : never : R + export type OutputContext = Scope.Scope | Exclude | Progress> + + export interface Options

{ + readonly initialProgress?: P + } } export const forkEffectPubSub = (