This commit is contained in:
@@ -23,24 +23,24 @@ const MemoizedProto = Object.freeze({
|
|||||||
|
|
||||||
export const isMemoized = (u: unknown): u is Memoized<unknown> => Predicate.hasProperty(u, TypeId)
|
export const isMemoized = (u: unknown): u is Memoized<unknown> => Predicate.hasProperty(u, TypeId)
|
||||||
|
|
||||||
export const memo = <T extends Component.Component<any, any, any>>(
|
export const memo = <T extends Component.Component<any, any, any, any>>(
|
||||||
self: T
|
self: T
|
||||||
): T & Memoized<Component.FunctionComponent.Props<Component.Component.FunctionComponent<T>>> => Object.setPrototypeOf(
|
): T & Memoized<Component.Component.Props<T>> => Object.setPrototypeOf(
|
||||||
Object.assign(function() {}, self),
|
Object.assign(function() {}, self),
|
||||||
Object.freeze({ ...Object.getPrototypeOf(self), ...MemoizedProto }),
|
Object.freeze({ ...Object.getPrototypeOf(self), ...MemoizedProto }),
|
||||||
)
|
)
|
||||||
|
|
||||||
export const withOptions: {
|
export const withOptions: {
|
||||||
<T extends Component.Component<any, any, any> & Memoized<any>>(
|
<T extends Component.Component<any, any, any, any> & Memoized<any>>(
|
||||||
options: Partial<Memoized.Options<Component.FunctionComponent.Props<Component.Component.FunctionComponent<T>>>>
|
options: Partial<Memoized.Options<Component.Component.Props<T>>>
|
||||||
): (self: T) => T
|
): (self: T) => T
|
||||||
<T extends Component.Component<any, any, any> & Memoized<any>>(
|
<T extends Component.Component<any, any, any, any> & Memoized<any>>(
|
||||||
self: T,
|
self: T,
|
||||||
options: Partial<Memoized.Options<Component.FunctionComponent.Props<Component.Component.FunctionComponent<T>>>>,
|
options: Partial<Memoized.Options<Component.Component.Props<T>>>,
|
||||||
): T
|
): T
|
||||||
} = Function.dual(2, <T extends Component.Component<any, any, any> & Memoized<any>>(
|
} = Function.dual(2, <T extends Component.Component<any, any, any, any> & Memoized<any>>(
|
||||||
self: T,
|
self: T,
|
||||||
options: Partial<Memoized.Options<Component.FunctionComponent.Props<Component.Component.FunctionComponent<T>>>>,
|
options: Partial<Memoized.Options<Component.Component.Props<T>>>,
|
||||||
): T => Object.setPrototypeOf(
|
): T => Object.setPrototypeOf(
|
||||||
Object.assign(function() {}, self, options),
|
Object.assign(function() {}, self, options),
|
||||||
Object.getPrototypeOf(self),
|
Object.getPrototypeOf(self),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Effect, Function, Predicate, Runtime, Scope } from "effect"
|
import { Effect, Function, Predicate, Runtime, Scope } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import type * as Component from "./Component.js"
|
import * as Component from "./Component.js"
|
||||||
|
|
||||||
|
|
||||||
export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense")
|
export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense")
|
||||||
@@ -22,8 +22,8 @@ export namespace Suspense {
|
|||||||
const SuspenseProto = Object.freeze({
|
const SuspenseProto = Object.freeze({
|
||||||
[TypeId]: TypeId,
|
[TypeId]: TypeId,
|
||||||
|
|
||||||
makeFunctionComponent<F extends Component.FunctionComponent, E, R>(
|
makeFunctionComponent<P, A extends React.ReactNode, E, R>(
|
||||||
this: Component.Component<F, E, R> & Suspense,
|
this: Component.Component<P, A, E, R> & Suspense,
|
||||||
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
|
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
|
||||||
scope: Scope.Scope,
|
scope: Scope.Scope,
|
||||||
) {
|
) {
|
||||||
@@ -31,7 +31,7 @@ const SuspenseProto = Object.freeze({
|
|||||||
|
|
||||||
return ({ fallback, name, ...props }: Suspense.Props) => {
|
return ({ fallback, name, ...props }: Suspense.Props) => {
|
||||||
const promise = Runtime.runPromise(runtimeRef.current)(
|
const promise = Runtime.runPromise(runtimeRef.current)(
|
||||||
Effect.provideService(this.body(props as Component.FunctionComponent.Props<F>), Scope.Scope, scope)
|
Effect.provideService(this.body(props as P), Scope.Scope, scope)
|
||||||
)
|
)
|
||||||
|
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
@@ -46,18 +46,16 @@ const SuspenseProto = Object.freeze({
|
|||||||
|
|
||||||
export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId)
|
export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId)
|
||||||
|
|
||||||
export const suspense = <T extends Component.Component<any, any, any>>(
|
export const suspense = <T extends Component.Component<any, any, any, any>>(
|
||||||
self: T
|
self: T
|
||||||
): (
|
): (
|
||||||
& Omit<T, keyof Component.Component.AsComponent<T>>
|
& Omit<T, keyof Component.Component.AsComponent<T>>
|
||||||
& Component.Component<
|
& Component.Component<
|
||||||
Component.Component.FunctionComponent<T> extends (...args: readonly [infer P, ...infer Args]) => infer A
|
Component.Component.Props<T> & Suspense.Props,
|
||||||
? A extends React.ReactNode
|
Component.Component.Success<T>,
|
||||||
? (...args: readonly [props: P & Suspense.Props, ...Args]) => A
|
|
||||||
: never
|
|
||||||
: never,
|
|
||||||
Component.Component.Error<T>,
|
Component.Component.Error<T>,
|
||||||
Component.Component.Context<T>>
|
Component.Component.Context<T>
|
||||||
|
>
|
||||||
& Suspense
|
& Suspense
|
||||||
) => Object.setPrototypeOf(
|
) => Object.setPrototypeOf(
|
||||||
Object.assign(function() {}, self),
|
Object.assign(function() {}, self),
|
||||||
@@ -65,14 +63,14 @@ export const suspense = <T extends Component.Component<any, any, any>>(
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const withOptions: {
|
export const withOptions: {
|
||||||
<T extends Component.Component<any, any, any> & Suspense>(
|
<T extends Component.Component<any, any, any, any> & Suspense>(
|
||||||
options: Partial<Suspense.Options>
|
options: Partial<Suspense.Options>
|
||||||
): (self: T) => T
|
): (self: T) => T
|
||||||
<T extends Component.Component<any, any, any> & Suspense>(
|
<T extends Component.Component<any, any, any, any> & Suspense>(
|
||||||
self: T,
|
self: T,
|
||||||
options: Partial<Suspense.Options>,
|
options: Partial<Suspense.Options>,
|
||||||
): T
|
): T
|
||||||
} = Function.dual(2, <T extends Component.Component<any, any, any> & Suspense>(
|
} = Function.dual(2, <T extends Component.Component<any, any, any, any> & Suspense>(
|
||||||
self: T,
|
self: T,
|
||||||
options: Partial<Suspense.Options>,
|
options: Partial<Suspense.Options>,
|
||||||
): T => Object.setPrototypeOf(
|
): T => Object.setPrototypeOf(
|
||||||
|
|||||||
Reference in New Issue
Block a user