diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index f1b14e9..21a160b 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -11,7 +11,7 @@ export type ComponentTypeId = typeof ComponentTypeId * Represents an Effect-based React Component that integrates the Effect system with React. */ export interface Component

-extends ComponentPrototype, ComponentOptions { +extends ComponentPrototype, ComponentOptions { new(_: never): Record readonly [ComponentTypeId]: ComponentTypeId readonly "~Props": P @@ -40,27 +40,22 @@ export declare namespace Component { } -export interface ComponentPrototype

-extends Pipeable.Pipeable { - readonly [ComponentTypeId]: ComponentTypeId +export interface ComponentImpl

+extends Component, ComponentImplPrototype {} + +export interface ComponentImplPrototype { readonly use: Effect.Effect> - asFunctionComponent( - runtimeRef: React.Ref>> - ): F - - setFunctionComponentName(f: React.FC

): void - transformFunctionComponent(f: React.FC

): React.FC

+ asFunctionComponent(runtimeRef: React.Ref>>): F + setFunctionComponentName(f: F): void + transformFunctionComponent(f: F): F } -export const ComponentPrototype: ComponentPrototype = Object.freeze({ - [ComponentTypeId]: ComponentTypeId, - ...Pipeable.Prototype, - +export const ComponentImplPrototype: ComponentImplPrototype = Object.freeze({ get use() { return use(this) }, asFunctionComponent

( - this: Component, + this: ComponentImpl, runtimeRef: React.RefObject>>, ) { return (props: P) => Runtime.runSync(runtimeRef.current)( @@ -72,7 +67,7 @@ export const ComponentPrototype: ComponentPrototype = Object.free }, setFunctionComponentName

( - this: Component, + this: ComponentImpl, f: React.FC

, ) { f.displayName = this.displayName ?? "Anonymous" @@ -82,7 +77,7 @@ export const ComponentPrototype: ComponentPrototype = Object.free } as const) const use = Effect.fnUntraced(function*

( - self: Component + self: ComponentImpl ) { // biome-ignore lint/style/noNonNullAssertion: React ref initialization const runtimeRef = React.useRef>>(null!) @@ -101,6 +96,19 @@ const use = Effect.fnUntraced(function*

+extends Pipeable.Pipeable { + readonly [ComponentTypeId]: ComponentTypeId + readonly use: Effect.Effect> +} + +export const ComponentPrototype: ComponentPrototype = Object.freeze({ + [ComponentTypeId]: ComponentTypeId, + ...Pipeable.Prototype, + ...ComponentImplPrototype, +} as const) + + export interface ComponentOptions { /** * Custom display name for the component in React DevTools and debugging utilities.