0.1.3 #4
@@ -27,7 +27,7 @@ export const memo = <T extends Component.Component<any, any, any>>(
|
||||
self: T
|
||||
): T & Memoized<Component.FunctionComponent.Props<Component.Component.FunctionComponent<T>>> => Object.setPrototypeOf(
|
||||
Object.assign(function() {}, self),
|
||||
Object.seal({ ...Object.getPrototypeOf(self), ...MemoizedProto }),
|
||||
Object.freeze({ ...Object.getPrototypeOf(self), ...MemoizedProto }),
|
||||
)
|
||||
|
||||
export const withOptions: {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Effect, Function, Predicate, Runtime, Scope } from "effect"
|
||||
import * as React from "react"
|
||||
import type * as Component from "./Component.js"
|
||||
import type { ExcludeKeys } from "./utils.js"
|
||||
|
||||
|
||||
export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense")
|
||||
@@ -22,16 +21,17 @@ export namespace Suspense {
|
||||
|
||||
const SuspenseProto = Object.freeze({
|
||||
[TypeId]: TypeId,
|
||||
makeFunctionComponent(
|
||||
this: Component.Component<any, any, any> & Suspense,
|
||||
runtimeRef: React.RefObject<Runtime.Runtime<any>>,
|
||||
|
||||
makeFunctionComponent<F extends Component.FunctionComponent, E, R>(
|
||||
this: Component.Component<F, E, R> & Suspense,
|
||||
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
|
||||
scope: Scope.Scope,
|
||||
): React.FC<any> {
|
||||
) {
|
||||
const SuspenseInner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise)
|
||||
|
||||
return ({ fallback, name, ...props }: Suspense.Props) => {
|
||||
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(
|
||||
@@ -46,15 +46,22 @@ const SuspenseProto = Object.freeze({
|
||||
|
||||
export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId)
|
||||
|
||||
export const suspense = <T extends Component.Component<P, any, any>, P extends {}>(
|
||||
self: T & Component.Component<ExcludeKeys<P, keyof Suspense.Props>, any, any>
|
||||
export const suspense = <T extends Component.Component<any, any, any>>(
|
||||
self: T
|
||||
): (
|
||||
& Omit<T, keyof Component.Component<P, Component.Component.Error<T>, Component.Component.Context<T>>>
|
||||
& Component.Component<P & Suspense.Props, Component.Component.Error<T>, Component.Component.Context<T>>
|
||||
& Omit<T, keyof Component.Component.AsComponent<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
|
||||
) => Object.setPrototypeOf(
|
||||
Object.assign(function() {}, self, SuspenseProto),
|
||||
Object.getPrototypeOf(self),
|
||||
Object.assign(function() {}, self),
|
||||
Object.freeze({ ...Object.getPrototypeOf(self), ...SuspenseProto }),
|
||||
)
|
||||
|
||||
export const withOptions: {
|
||||
|
||||
Reference in New Issue
Block a user