0.1.4 #5
@@ -71,16 +71,6 @@ export const make: {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const run = <A, I, R>(self: Form<A, I, R>) => Stream.runForEach(
|
|
||||||
self.encodedValueRef.changes,
|
|
||||||
flow(
|
|
||||||
Schema.decode(self.schema, { errors: "all" }),
|
|
||||||
Effect.andThen(v => SubscriptionRef.set(self.valueRef, Option.some(v))),
|
|
||||||
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
|
|
||||||
Effect.catchTag("ParseError", e => SubscriptionRef.set(self.errorRef, Option.some(e)))
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
export namespace service {
|
export namespace service {
|
||||||
export interface Options<in out A, in out I, out R> extends make.Options<A, I, R> {}
|
export interface Options<in out A, in out I, out R> extends make.Options<A, I, R> {}
|
||||||
}
|
}
|
||||||
@@ -104,6 +94,16 @@ export const useForm: {
|
|||||||
return form
|
return form
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const run = <A, I, R>(self: Form<A, I, R>) => Stream.runForEach(
|
||||||
|
self.encodedValueRef.changes,
|
||||||
|
flow(
|
||||||
|
Schema.decode(self.schema, { errors: "all" }),
|
||||||
|
Effect.andThen(v => SubscriptionRef.set(self.valueRef, Option.some(v))),
|
||||||
|
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
|
||||||
|
Effect.catchTag("ParseError", e => SubscriptionRef.set(self.errorRef, Option.some(e)))
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
export namespace useInput {
|
export namespace useInput {
|
||||||
export interface Options {
|
export interface Options {
|
||||||
@@ -139,18 +139,31 @@ export const useInput: {
|
|||||||
const [value, setValue] = yield* Hooks.useRefState(internalValueRef)
|
const [value, setValue] = yield* Hooks.useRefState(internalValueRef)
|
||||||
const [issues] = yield* Hooks.useSubscribables(issuesSubscribable)
|
const [issues] = yield* Hooks.useSubscribables(issuesSubscribable)
|
||||||
|
|
||||||
yield* Hooks.useFork(() => Stream.runForEach(
|
yield* Hooks.useFork(() => Effect.all([
|
||||||
internalValueRef.changes.pipe(
|
Stream.runForEach(
|
||||||
Stream.changesWith(Equivalence.strict()),
|
self.encodedValueRef.changes.pipe(
|
||||||
options?.debounce ? Stream.debounce(options.debounce) : identity,
|
Stream.flatMap(PropertyPath.get(path)),
|
||||||
Stream.drop(1),
|
Stream.drop(1),
|
||||||
|
),
|
||||||
|
|
||||||
|
upstreamEncodedValue => internalValueRef.pipe(
|
||||||
|
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
internalValue => self.encodedValueRef.pipe(
|
Stream.runForEach(
|
||||||
Effect.andThen(encodedValue => PropertyPath.immutableSet(encodedValue, path, internalValue)),
|
internalValueRef.changes.pipe(
|
||||||
Effect.andThen(encodedValue => SubscriptionRef.set(self.encodedValueRef, encodedValue)),
|
Stream.changesWith(Equivalence.strict()),
|
||||||
|
options?.debounce ? Stream.debounce(options.debounce) : identity,
|
||||||
|
Stream.drop(1),
|
||||||
|
),
|
||||||
|
|
||||||
|
internalValue => self.encodedValueRef.pipe(
|
||||||
|
Effect.andThen(encodedValue => PropertyPath.immutableSet(encodedValue, path, internalValue)),
|
||||||
|
Effect.andThen(encodedValue => SubscriptionRef.set(self.encodedValueRef, encodedValue)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
), [internalValueRef, self, ...path])
|
], { concurrency: "unbounded" }), [internalValueRef, self, ...path])
|
||||||
|
|
||||||
return { value, setValue, issues }
|
return { value, setValue, issues }
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user