diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index 297cd38..dd1524f 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -55,7 +55,7 @@ const ComponentProto = Object.freeze({ this: Component ) { const self = this - // biome-ignore lint/style/noNonNullAssertion: context initialization + // biome-ignore lint/style/noNonNullAssertion: React ref initialization const runtimeRef = React.useRef>>(null!) runtimeRef.current = yield* Effect.runtime>() diff --git a/packages/effect-fc/src/Form.ts b/packages/effect-fc/src/Form.ts index 2d00fb5..e829a11 100644 --- a/packages/effect-fc/src/Form.ts +++ b/packages/effect-fc/src/Form.ts @@ -16,7 +16,7 @@ extends Pipeable.Pipeable { readonly [FormTypeId]: FormTypeId readonly schema: Schema.Schema - readonly submitFn: (value: NoInfer) => Effect.Effect + readonly onSubmit: (value: NoInfer) => Effect.Effect readonly debounce: Option.Option readonly valueRef: SubscriptionRef.SubscriptionRef> @@ -34,7 +34,7 @@ extends Pipeable.Class() implements Form { constructor( readonly schema: Schema.Schema, - readonly submitFn: (value: NoInfer) => Effect.Effect, + readonly onSubmit: (value: NoInfer) => Effect.Effect, readonly debounce: Option.Option, readonly valueRef: SubscriptionRef.SubscriptionRef>, @@ -55,7 +55,7 @@ export namespace make { export interface Options { readonly schema: Schema.Schema readonly initialEncodedValue: NoInfer - readonly submitFn: (value: NoInfer) => Effect.Effect, + readonly onSubmit: (value: NoInfer) => Effect.Effect, readonly debounce?: Duration.DurationInput, } } @@ -74,7 +74,7 @@ export const make: { return new FormImpl( options.schema, - options.submitFn, + options.onSubmit, Option.fromNullable(options.debounce), valueRef, @@ -142,7 +142,7 @@ export const submit = ( Effect.andThen(identity), Effect.tap(Ref.set(self.submitStateRef, AsyncData.loading())), Effect.andThen(flow( - self.submitFn as (value: NoInfer) => Effect.Effect, + self.onSubmit as (value: NoInfer) => Effect.Effect, Effect.tapErrorTag("ParseError", e => Ref.set(self.errorRef, Option.some(e as ParseResult.ParseError))), Effect.exit, Effect.map(Exit.match({ diff --git a/packages/example/src/routes/form.tsx b/packages/example/src/routes/form.tsx index 0e391dd..722e2d8 100644 --- a/packages/example/src/routes/form.tsx +++ b/packages/example/src/routes/form.tsx @@ -39,7 +39,7 @@ class RegisterForm extends Effect.Service()("RegisterForm", { ), initialEncodedValue: { email: "", password: "", birth: Option.none() }, - submitFn: v => Effect.sleep("500 millis").pipe( + onSubmit: v => Effect.sleep("500 millis").pipe( Effect.andThen(Console.log(v)), Effect.andThen(Effect.sync(() => alert("Done!"))), ), @@ -47,7 +47,7 @@ class RegisterForm extends Effect.Service()("RegisterForm", { }) }) {} -class RegisterPage extends Component.makeUntraced("RegisterPage")(function*() { +class RegisterFormView extends Component.makeUntraced("RegisterFormView")(function*() { const form = yield* RegisterForm const submit = yield* Form.useSubmit(form) const [canSubmit] = yield* Hooks.useSubscribables(form.canSubmitSubscribable) @@ -84,16 +84,18 @@ class RegisterPage extends Component.makeUntraced("RegisterPage")(function*() { ) }) {} +const RegisterPage = Component.makeUntraced("RegisterPage")(function*() { + const RegisterFormViewFC = yield* Effect.provide( + RegisterFormView, + yield* Hooks.useContext(RegisterForm.Default, { finalizerExecutionMode: "fork" }), + ) + + return +}).pipe( + Component.withRuntime(runtime.context) +) + export const Route = createFileRoute("/form")({ - component: Component.makeUntraced("RegisterRoute")(function*() { - const RegisterRouteFC = yield* Effect.provide( - RegisterPage, - yield* Hooks.useContext(RegisterForm.Default, { finalizerExecutionMode: "fork" }), - ) - - return - }).pipe( - Component.withRuntime(runtime.context) - ) + component: RegisterPage })