This commit is contained in:
@@ -21,6 +21,10 @@ export namespace Component {
|
||||
}
|
||||
}
|
||||
|
||||
export interface ComponentClass<E, R, P extends {}> extends Component<E, R, P> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
const ComponentProto = Object.seal({
|
||||
pipe() { return Pipeable.pipeArguments(this, arguments) }
|
||||
@@ -378,28 +382,31 @@ export namespace Suspense {
|
||||
export type Props = Omit<React.SuspenseProps, "children">
|
||||
}
|
||||
|
||||
export const suspense = <T extends Component<any, any, P>, P extends {}>(
|
||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
|
||||
): T & Suspense => Object.setPrototypeOf(
|
||||
{ ...self, suspense: true, suspenseOptions: {} },
|
||||
Object.getPrototypeOf(self),
|
||||
)
|
||||
export const suspense = <T extends Component<any, any, P> | Component<any, any, P> & Suspense, P extends {}>(
|
||||
self: T & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
|
||||
): (
|
||||
& T
|
||||
& Component<Component.Error<T>, Component.Context<T>, P & Suspense.Props>
|
||||
& Suspense
|
||||
) => Object.setPrototypeOf({
|
||||
...self,
|
||||
suspense: true,
|
||||
suspenseOptions: Predicate.hasProperty(self, "suspense") ? { ...self.suspenseOptions } : {},
|
||||
}, Object.getPrototypeOf(self))
|
||||
|
||||
export const suspenseWithOptions: {
|
||||
<T extends Component<any, any, P>, P extends {}>(
|
||||
export const withSuspenseOptions: {
|
||||
<T extends Component<any, any, any> & Suspense>(
|
||||
suspenseOptions: Partial<Suspense.Options>
|
||||
): (
|
||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
|
||||
) => T & Suspense
|
||||
<T extends Component<any, any, P>, P extends {}>(
|
||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>,
|
||||
): (self: T) => T
|
||||
<T extends Component<any, any, any> & Suspense>(
|
||||
self: T,
|
||||
suspenseOptions: Partial<Suspense.Options>,
|
||||
): T & Suspense
|
||||
} = Function.dual(2, <T extends Component<any, any, P>, P extends {}>(
|
||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>,
|
||||
): T
|
||||
} = Function.dual(2, <T extends Component<any, any, any> & Suspense>(
|
||||
self: T,
|
||||
suspenseOptions: Partial<Suspense.Options>,
|
||||
): T & Suspense => Object.setPrototypeOf(
|
||||
{ ...self, suspense: true, suspenseOptions },
|
||||
): T => Object.setPrototypeOf(
|
||||
{ ...self, suspense: true, suspenseOptions: { ...self.suspenseOptions, ...suspenseOptions } },
|
||||
Object.getPrototypeOf(self),
|
||||
))
|
||||
|
||||
|
||||
@@ -28,12 +28,17 @@ const RouteComponent = Component.make(function* RouteComponent() {
|
||||
Component.withRuntime(runtime.context)
|
||||
)
|
||||
|
||||
const SubComponent = Component.make(function* SubComponent() {
|
||||
const SubComponent = Component.make(function* SubComponent(props: { readonly value?: string }) {
|
||||
const id = yield* makeUuid4.pipe(Effect.provide(GetRandomValues.CryptoRandom))
|
||||
return <Text>{id}</Text>
|
||||
})
|
||||
|
||||
const MemoizedSubComponent = Component.memo(SubComponent)
|
||||
const MemoizedSubComponent = SubComponent.pipe(
|
||||
Component.memo,
|
||||
Component.suspense,
|
||||
Component.memo,
|
||||
)
|
||||
type T = typeof MemoizedSubComponent extends Component.Memoized<infer P> ? P : never
|
||||
|
||||
export const Route = createFileRoute("/dev/memo")({
|
||||
component: RouteComponent,
|
||||
|
||||
Reference in New Issue
Block a user