This commit is contained in:
@@ -210,21 +210,15 @@ export const service = <A, I = A, R = never, SA = void, SE = A, SR = never, SP =
|
|||||||
export const field = <A, I, R, SA, SE, SR, SP, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
export const field = <A, I, R, SA, SE, SR, SP, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||||
self: Form<A, I, R, SA, SE, SR, SP>,
|
self: Form<A, I, R, SA, SE, SR, SP>,
|
||||||
path: P,
|
path: P,
|
||||||
): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => new FormFieldImpl(
|
): Effect.Effect<FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>>> => self.fieldCacheRef.pipe(
|
||||||
Subscribable.mapEffect(self.valueRef, Option.match({
|
Effect.map(HashMap.get(new FormFieldKey(path))),
|
||||||
onSome: v => Option.map(PropertyPath.get(v, path), Option.some),
|
Effect.flatMap(Option.match({
|
||||||
onNone: () => Option.some(Option.none()),
|
onSome: v => Effect.succeed(v as FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>>),
|
||||||
})),
|
onNone: () => Effect.tap(
|
||||||
SubscriptionSubRef.makeFromPath(self.encodedValueRef, path),
|
Effect.succeed(makeFormField(self, path)),
|
||||||
Subscribable.mapEffect(self.errorRef, Option.match({
|
v => Ref.update(self.fieldCacheRef, HashMap.set(new FormFieldKey(path), v as FormField<unknown, unknown>)),
|
||||||
onSome: flow(
|
|
||||||
ParseResult.ArrayFormatter.formatError,
|
|
||||||
Effect.map(Array.filter(issue => PropertyPath.equivalence(issue.path, path))),
|
|
||||||
),
|
),
|
||||||
onNone: () => Effect.succeed([]),
|
|
||||||
})),
|
})),
|
||||||
Subscribable.map(self.validationFiberRef, Option.isSome),
|
|
||||||
Subscribable.map(self.submitResultRef, result => Result.isRunning(result) || Result.isRefreshing(result)),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user