@@ -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),
|
||||
))
|
||||
Reference in New Issue
Block a user