diff --git a/packages/effect-fc/src/ReactComponent.ts b/packages/effect-fc/src/Component.ts similarity index 87% rename from packages/effect-fc/src/ReactComponent.ts rename to packages/effect-fc/src/Component.ts index 408f99b..2c043ba 100644 --- a/packages/effect-fc/src/ReactComponent.ts +++ b/packages/effect-fc/src/Component.ts @@ -2,7 +2,7 @@ import { Context, Effect, ExecutionStrategy, Exit, Function, Pipeable, Ref, Runt import * as React from "react" -export interface ReactComponent extends Pipeable.Pipeable { +export interface Component extends Pipeable.Pipeable { (props: P): Effect.Effect readonly displayName?: string readonly options: Options @@ -13,9 +13,9 @@ export interface Options { readonly finalizerExecutionStrategy: ExecutionStrategy.ExecutionStrategy } -export type Error = T extends ReactComponent ? E : never -export type Context = T extends ReactComponent ? R : never -export type Props = T extends ReactComponent ? P : never +export type Error = T extends Component ? E : never +export type Context = T extends Component ? R : never +export type Props = T extends Component ? P : never export const nonReactiveTags = [Tracer.ParentSpan] as const @@ -32,7 +32,7 @@ export const make = < >( body: (props: P) => Generator, options?: MakeOptions, -): ReactComponent< +): Component< [Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap>] ? E : never, [Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap>] ? R : never, P @@ -44,7 +44,7 @@ export const make = < ? Effect.fn(displayName)(body) : Effect.fn(body) : Effect.fnUntraced(body) - ) as ReactComponent + ) as Component f.pipe = function pipe() { return Pipeable.pipeArguments(this, arguments) }; (f as Types.Mutable).displayName = displayName; @@ -59,10 +59,10 @@ export const make = < export const useFC: { ( - self: ReactComponent + self: Component ): Effect.Effect, never, Exclude> } = Effect.fn("useFC")(function* ( - self: ReactComponent + self: Component ) { const runtimeRef = React.useRef>>(null!) runtimeRef.current = yield* Effect.runtime>() @@ -128,7 +128,7 @@ const closeScope = ( export const use: { ( - self: ReactComponent, + self: Component, fn: (Component: React.FC

) => React.ReactNode, ): Effect.Effect> } = Effect.fn("use")(function*(self, fn) { @@ -138,13 +138,13 @@ export const use: { export const withRuntime: { ( context: React.Context>, - ): (self: ReactComponent) => React.FC

+ ): (self: Component) => React.FC

( - self: ReactComponent, + self: Component, context: React.Context>, ): React.FC

} = Function.dual(2, ( - self: ReactComponent, + self: Component, context: React.Context>, ): React.FC

=> function WithRuntime(props) { const runtime = React.useContext(context) diff --git a/packages/effect-fc/src/ReactHook.ts b/packages/effect-fc/src/Hook.ts similarity index 100% rename from packages/effect-fc/src/ReactHook.ts rename to packages/effect-fc/src/Hook.ts diff --git a/packages/effect-fc/src/ReactManagedRuntime.ts b/packages/effect-fc/src/ReactManagedRuntime.ts index b861aaa..6f6b413 100644 --- a/packages/effect-fc/src/ReactManagedRuntime.ts +++ b/packages/effect-fc/src/ReactManagedRuntime.ts @@ -16,31 +16,31 @@ export const make = ( }) -export interface AsyncProviderProps extends React.SuspenseProps { +export interface ProviderProps extends React.SuspenseProps { readonly runtime: ReactManagedRuntime readonly children?: React.ReactNode } export function AsyncProvider( - { runtime, children, ...suspenseProps }: AsyncProviderProps + { runtime, children, ...suspenseProps }: ProviderProps ): React.ReactNode { const promise = React.useMemo(() => Effect.runPromise(runtime.runtime.runtimeEffect), [runtime]) return React.createElement( React.Suspense, suspenseProps, - React.createElement(AsyncProviderInner, { runtime, promise, children }), + React.createElement(ProviderInner, { runtime, promise, children }), ) } -interface AsyncProviderInnerProps { +interface ProviderInnerProps { readonly runtime: ReactManagedRuntime readonly promise: Promise> readonly children?: React.ReactNode } -function AsyncProviderInner( - { runtime, promise, children }: AsyncProviderInnerProps +function ProviderInner( + { runtime, promise, children }: ProviderInnerProps ): React.ReactNode { const value = React.use(promise) return React.createElement(runtime.context, { value }, children) diff --git a/packages/effect-fc/src/index.ts b/packages/effect-fc/src/index.ts index 8b8a4b1..4318eff 100644 --- a/packages/effect-fc/src/index.ts +++ b/packages/effect-fc/src/index.ts @@ -1,3 +1,3 @@ -export * as ReactComponent from "./ReactComponent.js" -export * as ReactHook from "./ReactHook.js" +export * as Component from "./Component.js" +export * as Hook from "./Hook.js" export * as ReactManagedRuntime from "./ReactManagedRuntime.js"