0.2.0 #18

Merged
Thilawyn merged 44 commits from next into master 2025-10-24 01:36:27 +02:00
3 changed files with 9 additions and 10 deletions
Showing only changes of commit 4a5f4c329d - Show all commits

View File

@@ -469,8 +469,7 @@ export const useOnMount: {
f: () => Effect.Effect<A, E, R>
) {
const runtime = yield* Effect.runtime<R>()
// biome-ignore lint/correctness/useExhaustiveDependencies: only computed on mount
return yield* React.useMemo(() => Runtime.runSync(runtime)(Effect.cached(f())), [])
return yield* React.useState(() => Runtime.runSync(runtime)(Effect.cached(f())))[0]
})
export const useOnChange: {

View File

@@ -116,18 +116,18 @@ export const run = <A, I, R, SA, SE, SR>(
onNone: () => Effect.void,
})),
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.exit,
Effect.andThen(flow(
Exit.matchEffect({
onSuccess: v => SubscriptionRef.set(self.valueRef, Option.some(v)).pipe(
Effect.andThen(SubscriptionRef.set(self.errorRef, Option.none())),
onSuccess: v => Ref.set(self.valueRef, Option.some(v)).pipe(
Effect.andThen(Ref.set(self.errorRef, Option.none())),
Effect.as(Option.some(v)),
),
onFailure: c => Chunk.findFirst(Cause.failures(c), e => e._tag === "ParseError").pipe(
Option.match({
onSome: e => SubscriptionRef.set(self.errorRef, Option.some(e)),
onSome: e => Ref.set(self.errorRef, Option.some(e)),
onNone: () => Effect.void,
}),
Effect.as(Option.none<A>()),
@@ -144,7 +144,7 @@ export const run = <A, I, R, SA, SE, SR>(
Effect.forkScoped,
)
),
Effect.andThen(fiber => SubscriptionRef.set(self.validationFiberRef, Option.some(fiber)))
Effect.andThen(fiber => Ref.set(self.validationFiberRef, Option.some(fiber)))
),
)

View File

@@ -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 Component from "./Component.js"
import * as SetStateAction from "./SetStateAction.js"
@@ -18,7 +18,7 @@ export const useSubscriptionRefState: {
const setValue = yield* Component.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
Effect.andThen(
SubscriptionRef.updateAndGet(ref, prevState => SetStateAction.value(setStateAction, prevState)),
Ref.updateAndGet(ref, prevState => SetStateAction.value(setStateAction, prevState)),
v => setReactStateValue(v),
),
[ref])
@@ -35,7 +35,7 @@ export const useSubscriptionRefFromState: {
Stream.changesWith(ref.changes, Equivalence.strict()),
v => Effect.sync(() => setValue(v)),
)), [setValue])
yield* Component.useReactEffect(() => SubscriptionRef.set(ref, value), [value])
yield* Component.useReactEffect(() => Ref.set(ref, value), [value])
return ref
})