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({
|
const ComponentProto = Object.seal({
|
||||||
pipe() { return Pipeable.pipeArguments(this, arguments) }
|
pipe() { return Pipeable.pipeArguments(this, arguments) }
|
||||||
@@ -378,28 +382,31 @@ export namespace Suspense {
|
|||||||
export type Props = Omit<React.SuspenseProps, "children">
|
export type Props = Omit<React.SuspenseProps, "children">
|
||||||
}
|
}
|
||||||
|
|
||||||
export const suspense = <T extends Component<any, any, P>, P extends {}>(
|
export const suspense = <T extends Component<any, any, P> | Component<any, any, P> & Suspense, P extends {}>(
|
||||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
|
self: T & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
|
||||||
): T & Suspense => Object.setPrototypeOf(
|
): (
|
||||||
{ ...self, suspense: true, suspenseOptions: {} },
|
& T
|
||||||
Object.getPrototypeOf(self),
|
& 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: {
|
export const withSuspenseOptions: {
|
||||||
<T extends Component<any, any, P>, P extends {}>(
|
<T extends Component<any, any, any> & Suspense>(
|
||||||
suspenseOptions: Partial<Suspense.Options>
|
suspenseOptions: Partial<Suspense.Options>
|
||||||
): (
|
): (self: T) => T
|
||||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>
|
<T extends Component<any, any, any> & Suspense>(
|
||||||
) => T & Suspense
|
self: T,
|
||||||
<T extends Component<any, any, P>, P extends {}>(
|
|
||||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>,
|
|
||||||
suspenseOptions: Partial<Suspense.Options>,
|
suspenseOptions: Partial<Suspense.Options>,
|
||||||
): T & Suspense
|
): T
|
||||||
} = Function.dual(2, <T extends Component<any, any, P>, P extends {}>(
|
} = Function.dual(2, <T extends Component<any, any, any> & Suspense>(
|
||||||
self: ExcludeKeys<T, keyof Suspense> & Component<any, any, ExcludeKeys<P, keyof Suspense.Props>>,
|
self: T,
|
||||||
suspenseOptions: Partial<Suspense.Options>,
|
suspenseOptions: Partial<Suspense.Options>,
|
||||||
): T & Suspense => Object.setPrototypeOf(
|
): T => Object.setPrototypeOf(
|
||||||
{ ...self, suspense: true, suspenseOptions },
|
{ ...self, suspense: true, suspenseOptions: { ...self.suspenseOptions, ...suspenseOptions } },
|
||||||
Object.getPrototypeOf(self),
|
Object.getPrototypeOf(self),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,17 @@ const RouteComponent = Component.make(function* RouteComponent() {
|
|||||||
Component.withRuntime(runtime.context)
|
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))
|
const id = yield* makeUuid4.pipe(Effect.provide(GetRandomValues.CryptoRandom))
|
||||||
return <Text>{id}</Text>
|
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")({
|
export const Route = createFileRoute("/dev/memo")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
|
|||||||
Reference in New Issue
Block a user