@@ -51,15 +51,19 @@ export const useOptionalInput: {
|
|||||||
// Sync the upstream state with the internal state
|
// Sync the upstream state with the internal state
|
||||||
// Only mutate the internal state if the upstream value is actually different. This avoids infinite re-render loops.
|
// Only mutate the internal state if the upstream value is actually different. This avoids infinite re-render loops.
|
||||||
Stream.runForEach(Stream.changesWith(options.ref.changes, Equivalence.strict()), Option.match({
|
Stream.runForEach(Stream.changesWith(options.ref.changes, Equivalence.strict()), Option.match({
|
||||||
onSome: upstreamValue => Effect.whenEffect(
|
onSome: upstreamValue => Effect.andThen(
|
||||||
Schema.encode(options.schema)(upstreamValue).pipe(
|
Ref.set(enabledRef, true),
|
||||||
Effect.andThen(encodedUpstreamValue => Ref.set(internalRef, encodedUpstreamValue)),
|
|
||||||
Effect.andThen(Ref.set(enabledRef, true)),
|
Effect.whenEffect(
|
||||||
),
|
Effect.andThen(
|
||||||
internalRef.pipe(
|
Schema.encode(options.schema)(upstreamValue),
|
||||||
Effect.andThen(Schema.decode(options.schema)),
|
encodedUpstreamValue => Ref.set(internalRef, encodedUpstreamValue),
|
||||||
Effect.andThen(decodedInternalValue => !(options.equivalence ?? Equal.equals)(upstreamValue, decodedInternalValue)),
|
),
|
||||||
Effect.catchTag("ParseError", () => Effect.succeed(false)),
|
internalRef.pipe(
|
||||||
|
Effect.andThen(Schema.decode(options.schema)),
|
||||||
|
Effect.andThen(decodedInternalValue => !(options.equivalence ?? Equal.equals)(upstreamValue, decodedInternalValue)),
|
||||||
|
Effect.catchTag("ParseError", () => Effect.succeed(false)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user