0.1.3 #4

Merged
Thilawyn merged 90 commits from next into master 2025-08-23 03:07:28 +02:00
2 changed files with 20 additions and 13 deletions
Showing only changes of commit 53bceb3a8a - Show all commits

View File

@@ -27,7 +27,7 @@ export const memo = <T extends Component.Component<any, any, any>>(
self: T self: T
): T & Memoized<Component.FunctionComponent.Props<Component.Component.FunctionComponent<T>>> => Object.setPrototypeOf( ): T & Memoized<Component.FunctionComponent.Props<Component.Component.FunctionComponent<T>>> => Object.setPrototypeOf(
Object.assign(function() {}, self), Object.assign(function() {}, self),
Object.seal({ ...Object.getPrototypeOf(self), ...MemoizedProto }), Object.freeze({ ...Object.getPrototypeOf(self), ...MemoizedProto }),
) )
export const withOptions: { export const withOptions: {

View File

@@ -1,7 +1,6 @@
import { Effect, Function, Predicate, Runtime, Scope } from "effect" import { Effect, Function, Predicate, Runtime, Scope } from "effect"
import * as React from "react" import * as React from "react"
import type * as Component from "./Component.js" import type * as Component from "./Component.js"
import type { ExcludeKeys } from "./utils.js"
export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense") export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense")
@@ -22,16 +21,17 @@ export namespace Suspense {
const SuspenseProto = Object.freeze({ const SuspenseProto = Object.freeze({
[TypeId]: TypeId, [TypeId]: TypeId,
makeFunctionComponent(
this: Component.Component<any, any, any> & Suspense, makeFunctionComponent<F extends Component.FunctionComponent, E, R>(
runtimeRef: React.RefObject<Runtime.Runtime<any>>, this: Component.Component<F, E, R> & Suspense,
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
scope: Scope.Scope, scope: Scope.Scope,
): React.FC<any> { ) {
const SuspenseInner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise) const SuspenseInner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise)
return ({ fallback, name, ...props }: Suspense.Props) => { return ({ fallback, name, ...props }: Suspense.Props) => {
const promise = Runtime.runPromise(runtimeRef.current)( const promise = Runtime.runPromise(runtimeRef.current)(
Effect.provideService(this.body(props), Scope.Scope, scope) Effect.provideService(this.body(props as Component.FunctionComponent.Props<F>), Scope.Scope, scope)
) )
return React.createElement( return React.createElement(
@@ -46,15 +46,22 @@ const SuspenseProto = Object.freeze({
export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId) export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId)
export const suspense = <T extends Component.Component<P, any, any>, P extends {}>( export const suspense = <T extends Component.Component<any, any, any>>(
self: T & Component.Component<ExcludeKeys<P, keyof Suspense.Props>, any, any> self: T
): ( ): (
& Omit<T, keyof Component.Component<P, Component.Component.Error<T>, Component.Component.Context<T>>> & Omit<T, keyof Component.Component.AsComponent<T>>
& Component.Component<P & Suspense.Props, Component.Component.Error<T>, Component.Component.Context<T>> & Component.Component<
Component.Component.FunctionComponent<T> extends (...args: readonly [infer P, ...infer Args]) => infer A
? A extends React.ReactNode
? (...args: readonly [props: P & Suspense.Props, ...Args]) => A
: never
: never,
Component.Component.Error<T>,
Component.Component.Context<T>>
& Suspense & Suspense
) => Object.setPrototypeOf( ) => Object.setPrototypeOf(
Object.assign(function() {}, self, SuspenseProto), Object.assign(function() {}, self),
Object.getPrototypeOf(self), Object.freeze({ ...Object.getPrototypeOf(self), ...SuspenseProto }),
) )
export const withOptions: { export const withOptions: {