Add Effect v4 support, Fast Refresh tooling, and revamped docs #56

Merged
Thilawyn merged 133 commits from next into master 2026-07-26 02:32:59 +02:00
Showing only changes of commit 8bbeed9b8d - Show all commits
+12 -7
View File
@@ -1,6 +1,6 @@
/** biome-ignore-all lint/complexity/noBannedTypes: {} is the default type for React props */ /** biome-ignore-all lint/complexity/noBannedTypes: {} is the default type for React props */
/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */ /** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */
import { Context, type Duration, Effect, Equivalence, Exit, Fiber, Function, HashMap, identity, Layer, Option, Pipeable, Predicate, Ref, Scope, Tracer } from "effect" import { Cause, Context, type Duration, Effect, Equal, Equivalence, Exit, Fiber, Function, HashMap, identity, Layer, Option, Pipeable, Predicate, Ref, Scope, Tracer } from "effect"
import * as React from "react" import * as React from "react"
@@ -698,13 +698,13 @@ export const useScope = Effect.fnUntraced(function*(
ScopeMap as unknown as Effect.Effect<ScopeMap["Service"]>, ScopeMap as unknown as Effect.Effect<ScopeMap["Service"]>,
scopeMap => scopeMap.ref, scopeMap => scopeMap.ref,
)), )),
Effect.let("key", () => ({})), Effect.let("key", () => Equal.byReference({})),
Effect.bind("scope", () => Scope.make(options?.finalizerExecutionStrategy ?? defaultOptions.finalizerExecutionStrategy)), Effect.bind("scope", () => Scope.make(options?.finalizerExecutionStrategy ?? defaultOptions.finalizerExecutionStrategy)),
Effect.tap(({ scopeMapRef, key, scope }) => Effect.tap(({ scopeMapRef, key, scope }) =>
Ref.update(scopeMapRef, HashMap.set(key, { Ref.update(scopeMapRef, HashMap.set(key, Equal.byReference({
scope, scope,
closeFiber: Option.none(), closeFiber: Option.none(),
})) })))
), ),
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList // biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
)), deps) )), deps)
@@ -724,13 +724,18 @@ export const useScope = Effect.fnUntraced(function*(
() => Effect.runSyncWith(contextRef.current)(Effect.flatMap( () => Effect.runSyncWith(contextRef.current)(Effect.flatMap(
Effect.sleep(options?.finalizerExecutionDebounce ?? defaultOptions.finalizerExecutionDebounce).pipe( Effect.sleep(options?.finalizerExecutionDebounce ?? defaultOptions.finalizerExecutionDebounce).pipe(
Effect.andThen(Scope.close(scope, Exit.void)), Effect.andThen(Scope.close(scope, Exit.void)),
Effect.onExit(() => Ref.update(ref, HashMap.remove(key))), Effect.onExit(exit => Exit.match(exit, {
onSuccess: () => Ref.update(ref, HashMap.remove(key)),
onFailure: cause => Cause.hasInterruptsOnly(cause)
? Effect.void
: Ref.update(ref, HashMap.remove(key)),
})),
Effect.forkDetach, Effect.forkDetach,
), ),
fiber => Ref.update(ref, HashMap.set(key, { fiber => Ref.update(ref, HashMap.set(key, Equal.byReference({
scope, scope,
closeFiber: Option.some(fiber), closeFiber: Option.some(fiber),
})), }))),
)) ))
), ),
) )