|
|
|
|
@@ -2,7 +2,7 @@ import { Context, Effect, ExecutionStrategy, Exit, Function, Pipeable, Ref, Runt
|
|
|
|
|
import * as React from "react"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface ReactComponent<E, R, P extends {}> extends Pipeable.Pipeable {
|
|
|
|
|
export interface Component<E, R, P extends {}> extends Pipeable.Pipeable {
|
|
|
|
|
(props: P): Effect.Effect<React.ReactNode, E, R>
|
|
|
|
|
readonly displayName?: string
|
|
|
|
|
readonly options: Options
|
|
|
|
|
@@ -13,9 +13,9 @@ export interface Options {
|
|
|
|
|
readonly finalizerExecutionStrategy: ExecutionStrategy.ExecutionStrategy
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type Error<T> = T extends ReactComponent<infer E, infer _R, infer _P> ? E : never
|
|
|
|
|
export type Context<T> = T extends ReactComponent<infer _E, infer R, infer _P> ? R : never
|
|
|
|
|
export type Props<T> = T extends ReactComponent<infer _E, infer _R, infer P> ? P : never
|
|
|
|
|
export type Error<T> = T extends Component<infer E, infer _R, infer _P> ? E : never
|
|
|
|
|
export type Context<T> = T extends Component<infer _E, infer R, infer _P> ? R : never
|
|
|
|
|
export type Props<T> = T extends Component<infer _E, infer _R, infer P> ? P : never
|
|
|
|
|
|
|
|
|
|
export const nonReactiveTags = [Tracer.ParentSpan] as const
|
|
|
|
|
|
|
|
|
|
@@ -32,7 +32,7 @@ export const make = <
|
|
|
|
|
>(
|
|
|
|
|
body: (props: P) => Generator<Eff, React.ReactNode, never>,
|
|
|
|
|
options?: MakeOptions,
|
|
|
|
|
): ReactComponent<
|
|
|
|
|
): Component<
|
|
|
|
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
|
|
|
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never,
|
|
|
|
|
P
|
|
|
|
|
@@ -44,7 +44,7 @@ export const make = <
|
|
|
|
|
? Effect.fn(displayName)(body)
|
|
|
|
|
: Effect.fn(body)
|
|
|
|
|
: Effect.fnUntraced(body)
|
|
|
|
|
) as ReactComponent<any, any, any>
|
|
|
|
|
) as Component<any, any, any>
|
|
|
|
|
|
|
|
|
|
f.pipe = function pipe() { return Pipeable.pipeArguments(this, arguments) };
|
|
|
|
|
(f as Types.Mutable<typeof f>).displayName = displayName;
|
|
|
|
|
@@ -59,10 +59,10 @@ export const make = <
|
|
|
|
|
|
|
|
|
|
export const useFC: {
|
|
|
|
|
<E, R, P extends {}>(
|
|
|
|
|
self: ReactComponent<E, R, P>
|
|
|
|
|
self: Component<E, R, P>
|
|
|
|
|
): Effect.Effect<React.FC<P>, never, Exclude<R, Scope.Scope>>
|
|
|
|
|
} = Effect.fn("useFC")(function* <E, R, P extends {}>(
|
|
|
|
|
self: ReactComponent<E, R, P>
|
|
|
|
|
self: Component<E, R, P>
|
|
|
|
|
) {
|
|
|
|
|
const runtimeRef = React.useRef<Runtime.Runtime<Exclude<R, Scope.Scope>>>(null!)
|
|
|
|
|
runtimeRef.current = yield* Effect.runtime<Exclude<R, Scope.Scope>>()
|
|
|
|
|
@@ -128,7 +128,7 @@ const closeScope = (
|
|
|
|
|
|
|
|
|
|
export const use: {
|
|
|
|
|
<E, R, P extends {}>(
|
|
|
|
|
self: ReactComponent<E, R, P>,
|
|
|
|
|
self: Component<E, R, P>,
|
|
|
|
|
fn: (Component: React.FC<P>) => React.ReactNode,
|
|
|
|
|
): Effect.Effect<React.ReactNode, never, Exclude<R, Scope.Scope>>
|
|
|
|
|
} = Effect.fn("use")(function*(self, fn) {
|
|
|
|
|
@@ -138,13 +138,13 @@ export const use: {
|
|
|
|
|
export const withRuntime: {
|
|
|
|
|
<E, R, P extends {}>(
|
|
|
|
|
context: React.Context<Runtime.Runtime<R>>,
|
|
|
|
|
): (self: ReactComponent<E, R | Scope.Scope, P>) => React.FC<P>
|
|
|
|
|
): (self: Component<E, R | Scope.Scope, P>) => React.FC<P>
|
|
|
|
|
<E, R, P extends {}>(
|
|
|
|
|
self: ReactComponent<E, R | Scope.Scope, P>,
|
|
|
|
|
self: Component<E, R | Scope.Scope, P>,
|
|
|
|
|
context: React.Context<Runtime.Runtime<R>>,
|
|
|
|
|
): React.FC<P>
|
|
|
|
|
} = Function.dual(2, <E, R, P extends {}>(
|
|
|
|
|
self: ReactComponent<E, R | Scope.Scope, P>,
|
|
|
|
|
self: Component<E, R | Scope.Scope, P>,
|
|
|
|
|
context: React.Context<Runtime.Runtime<R>>,
|
|
|
|
|
): React.FC<P> => function WithRuntime(props) {
|
|
|
|
|
const runtime = React.useContext(context)
|