This commit is contained in:
@@ -7,7 +7,7 @@ import * as Memoized from "./Memoized.js"
|
||||
export const TypeId: unique symbol = Symbol.for("effect-fc/Component")
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
export interface Component<E, R, P extends {}>
|
||||
export interface Component<P extends {} = {}, E = never, R = never>
|
||||
extends Effect.Effect<React.FC<P>, never, Exclude<R, Scope.Scope>>, Component.Options {
|
||||
new(_: never): {}
|
||||
readonly [TypeId]: TypeId
|
||||
@@ -18,9 +18,9 @@ extends Effect.Effect<React.FC<P>, never, Exclude<R, Scope.Scope>>, Component.Op
|
||||
}
|
||||
|
||||
export namespace Component {
|
||||
export type Error<T> = T extends Component<infer E, infer _R, infer _P> ? E : never
|
||||
export type Context<T> = T extends Component<infer _E, infer R, infer _P> ? R : never
|
||||
export type Props<T> = T extends Component<infer _E, infer _R, infer P> ? P : never
|
||||
export type Props<T> = T extends Component<infer P, infer _E, infer _R> ? P : never
|
||||
export type Error<T> = T extends Component<infer _P, infer E, infer _R> ? E : never
|
||||
export type Context<T> = T extends Component<infer _P, infer _E, infer R> ? R : never
|
||||
|
||||
export interface Options {
|
||||
readonly displayName?: string
|
||||
@@ -34,7 +34,7 @@ const ComponentProto = Object.freeze({
|
||||
...Effectable.CommitPrototype,
|
||||
[TypeId]: TypeId,
|
||||
|
||||
commit: Effect.fnUntraced(function* <E, R, P extends {}>(this: Component<E, R, P>) {
|
||||
commit: Effect.fnUntraced(function* <P extends {}, E, R>(this: Component<P, E, R>) {
|
||||
const self = this
|
||||
const runtimeRef = React.useRef<Runtime.Runtime<Exclude<R, Scope.Scope>>>(null!)
|
||||
runtimeRef.current = yield* Effect.runtime<Exclude<R, Scope.Scope>>()
|
||||
@@ -59,8 +59,8 @@ const ComponentProto = Object.freeze({
|
||||
}, [])
|
||||
}),
|
||||
|
||||
makeFunctionComponent <E, R, P extends {}>(
|
||||
this: Component<E, R, P>,
|
||||
makeFunctionComponent <P extends {}, E, R>(
|
||||
this: Component<P, E, R>,
|
||||
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
|
||||
scope: Scope.Scope,
|
||||
): React.FC<P> {
|
||||
@@ -77,17 +77,16 @@ const defaultOptions = {
|
||||
|
||||
const nonReactiveTags = [Tracer.ParentSpan] as const
|
||||
|
||||
|
||||
export const isComponent = (u: unknown): u is Component<unknown, unknown, {}> => Predicate.hasProperty(u, TypeId)
|
||||
export const isComponent = (u: unknown): u is Component<{}, unknown, unknown> => Predicate.hasProperty(u, TypeId)
|
||||
|
||||
export namespace make {
|
||||
export type Gen = {
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, React.ReactNode, never>,
|
||||
): Component<
|
||||
P,
|
||||
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never,
|
||||
P
|
||||
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||
>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
@@ -99,7 +98,7 @@ export namespace make {
|
||||
>,
|
||||
props: NoInfer<P>,
|
||||
) => B
|
||||
): Component<Effect.Effect.Error<B>, Effect.Effect.Context<B>, P>
|
||||
): Component<P, Effect.Effect.Error<B>, Effect.Effect.Context<B>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -111,7 +110,7 @@ export namespace make {
|
||||
props: NoInfer<P>,
|
||||
) => B,
|
||||
b: (_: B, props: NoInfer<P>) => C,
|
||||
): Component<Effect.Effect.Error<C>, Effect.Effect.Context<C>, P>
|
||||
): Component<P, Effect.Effect.Error<C>, Effect.Effect.Context<C>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -124,7 +123,7 @@ export namespace make {
|
||||
) => B,
|
||||
b: (_: B, props: NoInfer<P>) => C,
|
||||
c: (_: C, props: NoInfer<P>) => D,
|
||||
): Component<Effect.Effect.Error<D>, Effect.Effect.Context<D>, P>
|
||||
): Component<P, Effect.Effect.Error<D>, Effect.Effect.Context<D>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -138,7 +137,7 @@ export namespace make {
|
||||
b: (_: B, props: NoInfer<P>) => C,
|
||||
c: (_: C, props: NoInfer<P>) => D,
|
||||
d: (_: D, props: NoInfer<P>) => E,
|
||||
): Component<Effect.Effect.Error<E>, Effect.Effect.Context<E>, P>
|
||||
): Component<P, Effect.Effect.Error<E>, Effect.Effect.Context<E>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -153,7 +152,7 @@ export namespace make {
|
||||
c: (_: C, props: NoInfer<P>) => D,
|
||||
d: (_: D, props: NoInfer<P>) => E,
|
||||
e: (_: E, props: NoInfer<P>) => F,
|
||||
): Component<Effect.Effect.Error<F>, Effect.Effect.Context<F>, P>
|
||||
): Component<P, Effect.Effect.Error<F>, Effect.Effect.Context<F>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -169,7 +168,7 @@ export namespace make {
|
||||
d: (_: D, props: NoInfer<P>) => E,
|
||||
e: (_: E, props: NoInfer<P>) => F,
|
||||
f: (_: F, props: NoInfer<P>) => G,
|
||||
): Component<Effect.Effect.Error<G>, Effect.Effect.Context<G>, P>
|
||||
): Component<P, Effect.Effect.Error<G>, Effect.Effect.Context<G>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -186,7 +185,7 @@ export namespace make {
|
||||
e: (_: E, props: NoInfer<P>) => F,
|
||||
f: (_: F, props: NoInfer<P>) => G,
|
||||
g: (_: G, props: NoInfer<P>) => H,
|
||||
): Component<Effect.Effect.Error<H>, Effect.Effect.Context<H>, P>
|
||||
): Component<P, Effect.Effect.Error<H>, Effect.Effect.Context<H>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -204,7 +203,7 @@ export namespace make {
|
||||
f: (_: F, props: NoInfer<P>) => G,
|
||||
g: (_: G, props: NoInfer<P>) => H,
|
||||
h: (_: H, props: NoInfer<P>) => I,
|
||||
): Component<Effect.Effect.Error<I>, Effect.Effect.Context<I>, P>
|
||||
): Component<P, Effect.Effect.Error<I>, Effect.Effect.Context<I>>
|
||||
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I, J extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Generator<Eff, A, never>,
|
||||
a: (
|
||||
@@ -223,35 +222,35 @@ export namespace make {
|
||||
g: (_: G, props: NoInfer<P>) => H,
|
||||
h: (_: H, props: NoInfer<P>) => I,
|
||||
i: (_: I, props: NoInfer<P>) => J,
|
||||
): Component<Effect.Effect.Error<J>, Effect.Effect.Context<J>, P>
|
||||
): Component<P, Effect.Effect.Error<J>, Effect.Effect.Context<J>>
|
||||
}
|
||||
|
||||
export type NonGen = {
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||
body: (props: P) => Eff
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
b: (_: B, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
b: (_: B, props: NoInfer<P>) => C,
|
||||
c: (_: C, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
b: (_: B, props: NoInfer<P>) => C,
|
||||
c: (_: C, props: NoInfer<P>) => D,
|
||||
d: (_: D, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
@@ -259,7 +258,7 @@ export namespace make {
|
||||
c: (_: C, props: NoInfer<P>) => D,
|
||||
d: (_: D, props: NoInfer<P>) => E,
|
||||
e: (_: E, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
@@ -268,7 +267,7 @@ export namespace make {
|
||||
d: (_: D, props: NoInfer<P>) => E,
|
||||
e: (_: E, props: NoInfer<P>) => F,
|
||||
f: (_: F, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
@@ -278,7 +277,7 @@ export namespace make {
|
||||
e: (_: E, props: NoInfer<P>) => F,
|
||||
f: (_: F, props: NoInfer<P>) => G,
|
||||
g: (_: G, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
@@ -289,7 +288,7 @@ export namespace make {
|
||||
f: (_: F, props: NoInfer<P>) => G,
|
||||
g: (_: G, props: NoInfer<P>) => H,
|
||||
h: (_: H, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, I, P extends {} = {}>(
|
||||
body: (props: P) => A,
|
||||
a: (_: A, props: NoInfer<P>) => B,
|
||||
@@ -301,7 +300,7 @@ export namespace make {
|
||||
g: (_: G, props: NoInfer<P>) => H,
|
||||
h: (_: H, props: NoInfer<P>) => I,
|
||||
i: (_: I, props: NoInfer<P>) => Eff,
|
||||
): Component<Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>, P>
|
||||
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,15 +366,15 @@ export const withOptions: {
|
||||
))
|
||||
|
||||
export const withRuntime: {
|
||||
<E, R, P extends {}>(
|
||||
<P extends {}, E, R>(
|
||||
context: React.Context<Runtime.Runtime<R>>,
|
||||
): (self: Component<E, R, P>) => React.FC<P>
|
||||
<E, R, P extends {}>(
|
||||
self: Component<E, R, P>,
|
||||
): (self: Component<P, E, R>) => React.FC<P>
|
||||
<P extends {}, E, R>(
|
||||
self: Component<P, E, R>,
|
||||
context: React.Context<Runtime.Runtime<R>>,
|
||||
): React.FC<P>
|
||||
} = Function.dual(2, <E, R, P extends {}>(
|
||||
self: Component<E, R, P>,
|
||||
} = Function.dual(2, <P extends {}, E, R>(
|
||||
self: Component<P, E, R>,
|
||||
context: React.Context<Runtime.Runtime<R>>,
|
||||
): React.FC<P> => function WithRuntime(props) {
|
||||
const runtime = React.useContext(context)
|
||||
|
||||
@@ -46,11 +46,11 @@ const SuspenseProto = Object.freeze({
|
||||
|
||||
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>>
|
||||
export const suspense = <T extends Component.Component<P, any, any>, P extends {}>(
|
||||
self: T & Component.Component<ExcludeKeys<P, keyof Suspense.Props>, any, any>
|
||||
): (
|
||||
& Omit<T, keyof Component.Component<Component.Component.Error<T>, Component.Component.Context<T>, P>>
|
||||
& Component.Component<Component.Component.Error<T>, Component.Component.Context<T>, P & Suspense.Props>
|
||||
& 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>>
|
||||
& Suspense
|
||||
) => Object.setPrototypeOf(
|
||||
Object.assign(function() {}, self, SuspenseProto),
|
||||
|
||||
Reference in New Issue
Block a user