@@ -1,4 +1,4 @@
|
||||
import { type Duration, Effect, flow, Option, ParseResult, Ref, Schema, Stream, SubscriptionRef, Types } from "effect"
|
||||
import { type Duration, Effect, flow, identity, Option, type ParseResult, Ref, Schema, Stream, SubscriptionRef, type Types } from "effect"
|
||||
import * as React from "react"
|
||||
import { useCallbackSync } from "./useCallbackSync.js"
|
||||
import { useFork } from "./useFork.js"
|
||||
@@ -30,7 +30,7 @@ export const useInput: {
|
||||
const [error, setError] = React.useState(Option.none<ParseResult.ParseError>())
|
||||
|
||||
yield* useFork(() => Effect.all([
|
||||
Stream.runForEach(options.ref, upstreamValue =>
|
||||
Stream.runForEach(options.ref.changes, upstreamValue =>
|
||||
Effect.andThen(internalRef, internalValue =>
|
||||
upstreamValue !== internalValue
|
||||
? Effect.andThen(Schema.encode(options.schema)(upstreamValue), v => Ref.set(internalRef, v))
|
||||
@@ -39,7 +39,7 @@ export const useInput: {
|
||||
),
|
||||
|
||||
Stream.runForEach(
|
||||
options.debounce ? Stream.debounce(internalRef, options.debounce) : internalRef,
|
||||
internalRef.changes.pipe(options.debounce ? Stream.debounce(options.debounce) : identity),
|
||||
flow(
|
||||
Schema.decode(options.schema),
|
||||
Effect.andThen(v => Ref.set(options.ref, v)),
|
||||
|
||||
Reference in New Issue
Block a user