Refactoring
Lint / lint (push) Successful in 11s

This commit is contained in:
Julien Valverdé
2025-07-22 19:26:53 +02:00
parent 44a8a96380
commit aa8feb79fa
4 changed files with 110 additions and 94 deletions
+49
View File
@@ -0,0 +1,49 @@
import { Function, Predicate } from "effect"
import type * as Component from "./Component.js"
import type { ExcludeKeys } from "./utils.js"
export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense")
export type TypeId = typeof TypeId
export interface Suspense extends Suspense.Options {
readonly [TypeId]: true
}
export namespace Suspense {
export interface Options {
readonly defaultFallback?: React.ReactNode
}
export type Props = Omit<React.SuspenseProps, "children">
}
export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId)
export const suspense = <T extends Component.Component<any, any, P>, P extends {}>(
self: T & Component.Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
): (
& T
& Component.Component<Component.Component.Error<T>, Component.Component.Context<T>, P & Suspense.Props>
& Suspense
) => Object.setPrototypeOf(
{ ...self, [TypeId]: true },
Object.getPrototypeOf(self),
)
export const withOptions: {
<T extends Component.Component<any, any, any> & Suspense>(
options: Partial<Suspense.Options>
): (self: T) => T
<T extends Component.Component<any, any, any> & Suspense>(
self: T,
options: Partial<Suspense.Options>,
): T
} = Function.dual(2, <T extends Component.Component<any, any, any> & Suspense>(
self: T,
options: Partial<Suspense.Options>,
): T => Object.setPrototypeOf(
{ ...self, ...options },
Object.getPrototypeOf(self),
))