diff --git a/packages/effect-fc/src/Form.ts b/packages/effect-fc/src/Form.ts index e0829cb..0acc963 100644 --- a/packages/effect-fc/src/Form.ts +++ b/packages/effect-fc/src/Form.ts @@ -61,6 +61,16 @@ extends Pipeable.Class() implements Form { readonly fieldCache: Ref.Ref>>, ) { super() + + this.canSubmit = Subscribable.map( + Subscribable.zipLatestAll(this.value, this.error, this.validationFiber, this.mutation.result), + ([value, error, validationFiber, submitResult]) => ( + Option.isSome(value) && + Option.isNone(error) && + Option.isNone(validationFiber) && + !(Result.isRunning(submitResult) || Result.isRefreshing(submitResult)) + ), + ) } field>( @@ -78,17 +88,7 @@ extends Pipeable.Class() implements Form { ) } - get canSubmit(): Subscribable.Subscribable { - return Subscribable.map( - Subscribable.zipLatestAll(this.value, this.error, this.validationFiber, this.mutation.result), - ([value, error, validationFiber, submitResult]) => ( - Option.isSome(value) && - Option.isNone(error) && - Option.isNone(validationFiber) && - !(Result.isRunning(submitResult) || Result.isRefreshing(submitResult)) - ), - ) - } + readonly canSubmit: Subscribable.Subscribable get submit(): Effect.Effect>, Cause.NoSuchElementException> { return this.value.pipe( diff --git a/packages/example/src/routes/form.tsx b/packages/example/src/routes/form.tsx index b0bfef9..dabbe70 100644 --- a/packages/example/src/routes/form.tsx +++ b/packages/example/src/routes/form.tsx @@ -54,9 +54,9 @@ class RegisterForm extends Effect.Service()("RegisterForm", { ), initialEncodedValue: { email: "", password: "", birth: Option.none() }, - f: Effect.fnUntraced(function*([v]) { + f: Effect.fnUntraced(function*([value]) { yield* Effect.sleep("500 millis") - return yield* Schema.decode(RegisterFormSubmitSchema)(v) + return yield* Schema.decode(RegisterFormSubmitSchema)(value) }), debounce: "500 millis", })