0.2.1 #26
@@ -469,8 +469,7 @@ export const useOnMount: {
|
|||||||
f: () => Effect.Effect<A, E, R>
|
f: () => Effect.Effect<A, E, R>
|
||||||
) {
|
) {
|
||||||
const runtime = yield* Effect.runtime<R>()
|
const runtime = yield* Effect.runtime<R>()
|
||||||
// biome-ignore lint/correctness/useExhaustiveDependencies: only computed on mount
|
return yield* React.useState(() => Runtime.runSync(runtime)(Effect.cached(f())))[0]
|
||||||
return yield* React.useMemo(() => Runtime.runSync(runtime)(Effect.cached(f())), [])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const useOnChange: {
|
export const useOnChange: {
|
||||||
|
|||||||
@@ -116,18 +116,18 @@ export const run = <A, I, R, SA, SE, SR>(
|
|||||||
onNone: () => Effect.void,
|
onNone: () => Effect.void,
|
||||||
})),
|
})),
|
||||||
Effect.andThen(
|
Effect.andThen(
|
||||||
Effect.addFinalizer(() => SubscriptionRef.set(self.validationFiberRef, Option.none())).pipe(
|
Effect.addFinalizer(() => Ref.set(self.validationFiberRef, Option.none())).pipe(
|
||||||
Effect.andThen(Schema.decode(self.schema, { errors: "all" })(encodedValue)),
|
Effect.andThen(Schema.decode(self.schema, { errors: "all" })(encodedValue)),
|
||||||
Effect.exit,
|
Effect.exit,
|
||||||
Effect.andThen(flow(
|
Effect.andThen(flow(
|
||||||
Exit.matchEffect({
|
Exit.matchEffect({
|
||||||
onSuccess: v => SubscriptionRef.set(self.valueRef, Option.some(v)).pipe(
|
onSuccess: v => Ref.set(self.valueRef, Option.some(v)).pipe(
|
||||||
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
|
Effect.andThen(Ref.set(self.errorRef, Option.none())),
|
||||||
Effect.as(Option.some(v)),
|
Effect.as(Option.some(v)),
|
||||||
),
|
),
|
||||||
onFailure: c => Chunk.findFirst(Cause.failures(c), e => e._tag === "ParseError").pipe(
|
onFailure: c => Chunk.findFirst(Cause.failures(c), e => e._tag === "ParseError").pipe(
|
||||||
Option.match({
|
Option.match({
|
||||||
onSome: e => SubscriptionRef.set(self.errorRef, Option.some(e)),
|
onSome: e => Ref.set(self.errorRef, Option.some(e)),
|
||||||
onNone: () => Effect.void,
|
onNone: () => Effect.void,
|
||||||
}),
|
}),
|
||||||
Effect.as(Option.none<A>()),
|
Effect.as(Option.none<A>()),
|
||||||
@@ -144,7 +144,7 @@ export const run = <A, I, R, SA, SE, SR>(
|
|||||||
Effect.forkScoped,
|
Effect.forkScoped,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Effect.andThen(fiber => SubscriptionRef.set(self.validationFiberRef, Option.some(fiber)))
|
Effect.andThen(fiber => Ref.set(self.validationFiberRef, Option.some(fiber)))
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Effect, Equivalence, type Scope, Stream, SubscriptionRef } from "effect"
|
import { Effect, Equivalence, Ref, type Scope, Stream, SubscriptionRef } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import * as Component from "./Component.js"
|
import * as Component from "./Component.js"
|
||||||
import * as SetStateAction from "./SetStateAction.js"
|
import * as SetStateAction from "./SetStateAction.js"
|
||||||
@@ -18,7 +18,7 @@ export const useSubscriptionRefState: {
|
|||||||
|
|
||||||
const setValue = yield* Component.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
const setValue = yield* Component.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
||||||
Effect.andThen(
|
Effect.andThen(
|
||||||
SubscriptionRef.updateAndGet(ref, prevState => SetStateAction.value(setStateAction, prevState)),
|
Ref.updateAndGet(ref, prevState => SetStateAction.value(setStateAction, prevState)),
|
||||||
v => setReactStateValue(v),
|
v => setReactStateValue(v),
|
||||||
),
|
),
|
||||||
[ref])
|
[ref])
|
||||||
@@ -35,7 +35,7 @@ export const useSubscriptionRefFromState: {
|
|||||||
Stream.changesWith(ref.changes, Equivalence.strict()),
|
Stream.changesWith(ref.changes, Equivalence.strict()),
|
||||||
v => Effect.sync(() => setValue(v)),
|
v => Effect.sync(() => setValue(v)),
|
||||||
)), [setValue])
|
)), [setValue])
|
||||||
yield* Component.useReactEffect(() => SubscriptionRef.set(ref, value), [value])
|
yield* Component.useReactEffect(() => Ref.set(ref, value), [value])
|
||||||
|
|
||||||
return ref
|
return ref
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user