diff --git a/packages/effect-fc/src/Form.ts b/packages/effect-fc/src/Form.ts index 1233a1b..4969ad2 100644 --- a/packages/effect-fc/src/Form.ts +++ b/packages/effect-fc/src/Form.ts @@ -210,21 +210,15 @@ export const service = >>( self: Form, path: P, -): FormField, PropertyPath.ValueFromPath> => new FormFieldImpl( - Subscribable.mapEffect(self.valueRef, Option.match({ - onSome: v => Option.map(PropertyPath.get(v, path), Option.some), - onNone: () => Option.some(Option.none()), - })), - SubscriptionSubRef.makeFromPath(self.encodedValueRef, path), - Subscribable.mapEffect(self.errorRef, Option.match({ - onSome: flow( - ParseResult.ArrayFormatter.formatError, - Effect.map(Array.filter(issue => PropertyPath.equivalence(issue.path, path))), +): Effect.Effect, PropertyPath.ValueFromPath>> => self.fieldCacheRef.pipe( + Effect.map(HashMap.get(new FormFieldKey(path))), + Effect.flatMap(Option.match({ + onSome: v => Effect.succeed(v as FormField, PropertyPath.ValueFromPath>), + onNone: () => Effect.tap( + Effect.succeed(makeFormField(self, path)), + v => Ref.update(self.fieldCacheRef, HashMap.set(new FormFieldKey(path), v as FormField)), ), - onNone: () => Effect.succeed([]), })), - Subscribable.map(self.validationFiberRef, Option.isSome), - Subscribable.map(self.submitResultRef, result => Result.isRunning(result) || Result.isRefreshing(result)), )