diff --git a/packages/effect-fc/src/Form.ts b/packages/effect-fc/src/Form.ts index 3f8fa6a..1233a1b 100644 --- a/packages/effect-fc/src/Form.ts +++ b/packages/effect-fc/src/Form.ts @@ -1,4 +1,4 @@ -import { Array, Cause, Chunk, type Duration, Effect, Equal, Exit, Fiber, flow, Hash, identity, Option, ParseResult, Pipeable, Predicate, Ref, Schema, type Scope, Stream } from "effect" +import { Array, Cause, Chunk, type Duration, Effect, Equal, Exit, Fiber, flow, Hash, HashMap, identity, Option, ParseResult, Pipeable, Predicate, Ref, Schema, type Scope, Stream } from "effect" import type { NoSuchElementException } from "effect/Cause" import type * as React from "react" import * as Component from "./Component.js" @@ -22,6 +22,7 @@ extends Pipeable.Pipeable { readonly autosubmit: boolean readonly debounce: Option.Option + readonly fieldCacheRef: Ref.Ref>> readonly valueRef: SubscriptionRef.SubscriptionRef> readonly encodedValueRef: SubscriptionRef.SubscriptionRef readonly errorRef: SubscriptionRef.SubscriptionRef> @@ -42,6 +43,7 @@ extends Pipeable.Class() implements Form { readonly autosubmit: boolean, readonly debounce: Option.Option, + readonly fieldCacheRef: Ref.Ref>>, readonly valueRef: SubscriptionRef.SubscriptionRef>, readonly encodedValueRef: SubscriptionRef.SubscriptionRef, readonly errorRef: SubscriptionRef.SubscriptionRef>, @@ -54,21 +56,6 @@ extends Pipeable.Class() implements Form { } } -const FormFieldKeySymbol = Symbol.for("@effect-fc/Form/FormFieldKeySymbol") -class FormFieldKey implements Equal.Equal { - [FormFieldKeySymbol] = FormFieldKeySymbol - constructor(readonly a: PropertyPath.PropertyPath) {} - - [Equal.symbol](that: Equal.Equal) { - return Predicate.hasProperty(that, FormFieldKeySymbol) - ? PropertyPath.equivalence(this.a, (that as unknown as FormFieldKey).a) - : false - } - [Hash.symbol]() { - return 0 - } -} - export const isForm = (u: unknown): u is Form => Predicate.hasProperty(u, FormTypeId) export namespace make { @@ -104,6 +91,7 @@ export const make = Effect.fnUntraced(function* >()), valueRef, yield* SubscriptionRef.make(options.initialEncodedValue), errorRef, @@ -269,7 +257,23 @@ extends Pipeable.Class() implements FormField { } } +const FormFieldKeyTypeId: unique symbol = Symbol.for("@effect-fc/Form/FormFieldKey") +type FormFieldKeyTypeId = typeof FormFieldKeyTypeId + +class FormFieldKey implements Equal.Equal { + readonly [FormFieldKeyTypeId]: FormFieldKeyTypeId = FormFieldKeyTypeId + constructor(readonly path: PropertyPath.PropertyPath) {} + + [Equal.symbol](that: Equal.Equal) { + return isFormFieldKey(that) && PropertyPath.equivalence(this.path, that.path) + } + [Hash.symbol]() { + return 0 + } +} + export const isFormField = (u: unknown): u is FormField => Predicate.hasProperty(u, FormFieldTypeId) +const isFormFieldKey = (u: unknown): u is FormFieldKey => Predicate.hasProperty(u, FormFieldKeyTypeId) export const makeFormField = >>( self: Form,