0.1.4 #5
@@ -11,6 +11,7 @@ export type TypeId = typeof TypeId
|
|||||||
export interface Form<in out A, in out I = A, out R = never>
|
export interface Form<in out A, in out I = A, out R = never>
|
||||||
extends Pipeable.Pipeable {
|
extends Pipeable.Pipeable {
|
||||||
readonly schema: Schema.Schema<A, I, R>,
|
readonly schema: Schema.Schema<A, I, R>,
|
||||||
|
/** A reference to the latest valid value produced by the form, if any. */
|
||||||
readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>>,
|
readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>>,
|
||||||
readonly encodedValueRef: SubscriptionRef.SubscriptionRef<I>,
|
readonly encodedValueRef: SubscriptionRef.SubscriptionRef<I>,
|
||||||
readonly errorRef: SubscriptionRef.SubscriptionRef<Option.Option<ParseResult.ParseError>>,
|
readonly errorRef: SubscriptionRef.SubscriptionRef<Option.Option<ParseResult.ParseError>>,
|
||||||
@@ -73,7 +74,7 @@ export const make: {
|
|||||||
const run = <A, I, R>(self: Form<A, I, R>) => Stream.runForEach(
|
const run = <A, I, R>(self: Form<A, I, R>) => Stream.runForEach(
|
||||||
self.encodedValueRef.changes,
|
self.encodedValueRef.changes,
|
||||||
flow(
|
flow(
|
||||||
Schema.decode(self.schema),
|
Schema.decode(self.schema, { errors: "all" }),
|
||||||
Effect.andThen(v => SubscriptionRef.set(self.valueRef, Option.some(v))),
|
Effect.andThen(v => SubscriptionRef.set(self.valueRef, Option.some(v))),
|
||||||
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
|
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
|
||||||
Effect.catchTag("ParseError", e => SubscriptionRef.set(self.errorRef, Option.some(e)))
|
Effect.catchTag("ParseError", e => SubscriptionRef.set(self.errorRef, Option.some(e)))
|
||||||
|
|||||||
@@ -6,8 +6,18 @@ import { Component, Form } from "effect-fc"
|
|||||||
import { useContext, useFork } from "effect-fc/hooks"
|
import { useContext, useFork } from "effect-fc/hooks"
|
||||||
|
|
||||||
|
|
||||||
|
const email = Schema.pattern<typeof Schema.String>(
|
||||||
|
/^(?!\.)(?!.*\.\.)([A-Z0-9_+-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i,
|
||||||
|
|
||||||
|
{
|
||||||
|
identifier: "email",
|
||||||
|
title: "email",
|
||||||
|
message: () => "Not an email address",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const RegisterFormSchema = Schema.Struct({
|
const RegisterFormSchema = Schema.Struct({
|
||||||
email: Schema.String,
|
email: Schema.String.pipe(email),
|
||||||
password: Schema.String.pipe(Schema.minLength(3)),
|
password: Schema.String.pipe(Schema.minLength(3)),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -24,6 +34,7 @@ class RegisterPage extends Component.makeUntraced(function* RegisterPage() {
|
|||||||
const passwordInput = yield* Form.useInput(form, ["password"], { debounce: "200 millis" })
|
const passwordInput = yield* Form.useInput(form, ["password"], { debounce: "200 millis" })
|
||||||
|
|
||||||
yield* useFork(() => Stream.runForEach(form.valueRef.changes, Console.log), [])
|
yield* useFork(() => Stream.runForEach(form.valueRef.changes, Console.log), [])
|
||||||
|
// yield* useFork(() => Stream.runForEach(form.errorRef.changes, Console.log), [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
|||||||
Reference in New Issue
Block a user