import { Context, Effect, Effectable, ExecutionStrategy, Function, Predicate, Runtime, Scope, String, Tracer, type Utils } from "effect" import * as React from "react" import * as Hook from "./Hook.js" import * as Memoized from "./Memoized.js" export const TypeId: unique symbol = Symbol.for("effect-fc/Component") export type TypeId = typeof TypeId export interface Component
extends Effect.Effect
/** @internal */
readonly body: (props: P) => Effect.Effect (this: Component ) {
const self = this
const runtimeRef = React.useRef (
this: Component ,
runtimeRef: React.RefObject {
return (props: P) => Runtime.runSync(runtimeRef.current)(
Effect.provideService(this.body(props), Scope.Scope, scope)
)
},
} as const)
const defaultOptions = {
finalizerExecutionMode: "sync",
finalizerExecutionStrategy: ExecutionStrategy.sequential,
} as const
const nonReactiveTags = [Tracer.ParentSpan] as const
export const isComponent = (u: unknown): u is Component<{}, unknown, unknown> => Predicate.hasProperty(u, TypeId)
export namespace make {
export type Gen = {
,
) => B
): Component , Effect.Effect.Context>
,
) => B,
b: (_: B, props: NoInfer ) => C,
): Component , Effect.Effect.Context ,
) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
): Component , Effect.Effect.Context ,
) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
): Component , Effect.Effect.Context ,
) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
): Component , Effect.Effect.Context ,
) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => G,
): Component , Effect.Effect.Context ,
) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => G,
g: (_: G, props: NoInfer ) => H,
): Component , Effect.Effect.Context ,
) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => G,
g: (_: G, props: NoInfer ) => H,
h: (_: H, props: NoInfer ) => I,
): Component , Effect.Effect.Context>
,
) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => G,
g: (_: G, props: NoInfer ) => H,
h: (_: H, props: NoInfer ) => I,
i: (_: I, props: NoInfer ) => J,
): Component , Effect.Effect.Context , Effect.Effect.Context ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => G,
g: (_: G, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => G,
g: (_: G, props: NoInfer ) => H,
h: (_: H, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context ) => B,
b: (_: B, props: NoInfer ) => C,
c: (_: C, props: NoInfer ) => D,
d: (_: D, props: NoInfer ) => E,
e: (_: E, props: NoInfer ) => F,
f: (_: F, props: NoInfer ) => G,
g: (_: G, props: NoInfer ) => H,
h: (_: H, props: NoInfer ) => I,
i: (_: I, props: NoInfer ) => Eff,
): Component , Effect.Effect.Context (
context: React.Context ) => React.FC
(
self: Component ,
context: React.Context
} = Function.dual(2, (
self: Component ,
context: React.Context => function WithRuntime(props) {
const runtime = React.useContext(context)
return React.createElement(Runtime.runSync(runtime)(self), props)
})