API change
All checks were successful
Lint / lint (push) Successful in 31s

This commit is contained in:
Julien Valverdé
2025-06-25 21:51:46 +02:00
parent 8007c2693a
commit 79cf1e5eb7
3 changed files with 15 additions and 22 deletions

View File

@@ -3,23 +3,13 @@ import type * as React from "react"
export interface ReactComponent<P, E, R> {
readonly fn: (props: P) => Effect.Effect<React.ReactNode, E, R | Scope.Scope>
use(callback: (Component: React.FC<P>) => React.ReactNode): Effect.Effect<React.ReactNode, never, R>
(props: P): Effect.Effect<React.ReactNode, E, R | Scope.Scope>
}
const ReactComponentPrototype: Omit<ReactComponent<any, any, any>, "fn"> = {
use(this: ReactComponent<any, any, any>, callback) {
return Effect.map(
Effect.runtime(),
runtime => callback(props => Runtime.runSync(runtime)(this.fn(props))),
)
}
}
export const make = <P, E, R>(
fn: (props: P) => Effect.Effect<React.ReactNode, E, R | Scope.Scope>
): ReactComponent<P, E, R> => Object.setPrototypeOf(
{ fn },
ReactComponentPrototype,
export const use = <P, E, R>(
self: ReactComponent<P, E, R>,
fn: (Component: React.FC<P>) => React.ReactNode
): Effect.Effect<React.ReactNode, never, R | Scope.Scope> => Effect.map(
Effect.runtime(),
runtime => fn(props => Runtime.runSync(runtime)(self(props))),
)

View File

@@ -1 +1,2 @@
export * as ReactComponent from "./ReactComponent.js"
export { use } from "./ReactComponent.js"