Fix
All checks were successful
Lint / lint (push) Successful in 12s

This commit is contained in:
Julien Valverdé
2025-08-18 21:24:28 +02:00
parent ea5b5f9ac2
commit e665a9d691
2 changed files with 11 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
import { type Duration, Effect, flow, identity, Option, type ParseResult, Ref, Schema, Stream, SubscriptionRef } from "effect" import { type Duration, Effect, Equal, flow, identity, Option, type ParseResult, Ref, Schema, Stream, SubscriptionRef } from "effect"
import * as React from "react" import * as React from "react"
import { useFork } from "./useFork.js" import { useFork } from "./useFork.js"
import { useOnce } from "./useOnce.js" import { useOnce } from "./useOnce.js"
@@ -34,11 +34,14 @@ export const useInput: {
// Sync the upstream state with the internal state // Sync the upstream state with the internal state
// Only mutate the internal state if the upstream encoded value is actually different. This avoids infinite re-render loops. // Only mutate the internal state if the upstream encoded value is actually different. This avoids infinite re-render loops.
Stream.runForEach(options.ref.changes, upstreamValue => Stream.runForEach(options.ref.changes, upstreamValue =>
Effect.whenEffect(
Effect.andThen( Effect.andThen(
Effect.all([Schema.encode(options.schema)(upstreamValue), internalRef]), Schema.encode(options.schema)(upstreamValue),
([encodedUpstreamValue, internalValue]) => Effect.when( encodedUpstreamValue => Ref.set(internalRef, encodedUpstreamValue),
Ref.set(internalRef, encodedUpstreamValue), ),
() => encodedUpstreamValue !== internalValue, internalRef.pipe(
Effect.andThen(Schema.decode(options.schema)),
Effect.andThen(decodedInternalValue => !Equal.equals(upstreamValue, decodedInternalValue)),
), ),
) )
), ),

View File

@@ -2,9 +2,9 @@ import { TextFieldInput } from "@/lib/TextFieldInput"
import { runtime } from "@/runtime" import { runtime } from "@/runtime"
import { Container, TextField } from "@radix-ui/themes" import { Container, TextField } from "@radix-ui/themes"
import { createFileRoute } from "@tanstack/react-router" import { createFileRoute } from "@tanstack/react-router"
import { Console, Schema, Stream, SubscriptionRef } from "effect" import { Schema, SubscriptionRef } from "effect"
import { Component, Memo } from "effect-fc" import { Component, Memo } from "effect-fc"
import { useFork, useInput, useOnce, useRefState } from "effect-fc/hooks" import { useInput, useOnce } from "effect-fc/hooks"
const IntFromString = Schema.NumberFromString.pipe(Schema.int()) const IntFromString = Schema.NumberFromString.pipe(Schema.int())