0.1.3 #4

Merged
Thilawyn merged 90 commits from next into master 2025-08-23 03:07:28 +02:00
3 changed files with 21 additions and 21 deletions
Showing only changes of commit 3343b245d7 - Show all commits

View File

@@ -7,7 +7,7 @@ import * as Memoized from "./Memoized.js"
export const TypeId: unique symbol = Symbol.for("effect-fc/Component") export const TypeId: unique symbol = Symbol.for("effect-fc/Component")
export type TypeId = typeof TypeId export type TypeId = typeof TypeId
export interface Component<P, A extends React.ReactNode, E, R> export interface Component<P extends {}, A extends React.ReactNode, E, R>
extends extends
Effect.Effect<(props: P) => A, never, Exclude<R, Scope.Scope>>, Effect.Effect<(props: P) => A, never, Exclude<R, Scope.Scope>>,
Component.Options Component.Options
@@ -49,7 +49,7 @@ const ComponentProto = Object.freeze({
...Effectable.CommitPrototype, ...Effectable.CommitPrototype,
[TypeId]: TypeId, [TypeId]: TypeId,
commit: Effect.fnUntraced(function* <P, A extends React.ReactNode, E, R>( commit: Effect.fnUntraced(function* <P extends {}, A extends React.ReactNode, E, R>(
this: Component<P, A, E, R> this: Component<P, A, E, R>
) { ) {
const self = this const self = this
@@ -72,11 +72,11 @@ const ComponentProto = Object.freeze({
: f : f
}, [scope]) }, [scope])
return React.createElement(FC as React.FC<{}>, props as {}) return React.createElement(FC, props)
}, []) }, [])
}), }),
makeFunctionComponent<P, A extends React.ReactNode, E, R>( makeFunctionComponent<P extends {}, A extends React.ReactNode, E, R>(
this: Component<P, A, E, R>, this: Component<P, A, E, R>,
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>, runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
scope: Scope.Scope, scope: Scope.Scope,
@@ -95,18 +95,18 @@ const defaultOptions = {
const nonReactiveTags = [Tracer.ParentSpan] as const const nonReactiveTags = [Tracer.ParentSpan] as const
export const isComponent = (u: unknown): u is Component<unknown, React.ReactNode, unknown, unknown> => Predicate.hasProperty(u, TypeId) export const isComponent = (u: unknown): u is Component<{}, React.ReactNode, unknown, unknown> => Predicate.hasProperty(u, TypeId)
export namespace make { export namespace make {
export type Gen = { export type Gen = {
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A extends React.ReactNode, P = never>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A extends React.ReactNode, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never> body: (props: P) => Generator<Eff, A, never>
): Component< ): Component<
P, A, P, A,
[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>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never [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 = 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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -117,7 +117,7 @@ export namespace make {
props: NoInfer<P>, props: NoInfer<P>,
) => B, ) => B,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<B>>, Effect.Effect.Error<B>, Effect.Effect.Context<B>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<B>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -129,7 +129,7 @@ export namespace make {
) => B, ) => B,
b: (_: B, props: NoInfer<P>) => C, b: (_: B, props: NoInfer<P>) => C,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<C>>, Effect.Effect.Error<C>, Effect.Effect.Context<C>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<C>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -142,7 +142,7 @@ export namespace make {
b: (_: B, props: NoInfer<P>) => C, b: (_: B, props: NoInfer<P>) => C,
c: (_: C, props: NoInfer<P>) => D, c: (_: C, props: NoInfer<P>) => D,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<D>>, Effect.Effect.Error<D>, Effect.Effect.Context<D>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<D>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -156,7 +156,7 @@ export namespace make {
c: (_: C, props: NoInfer<P>) => D, c: (_: C, props: NoInfer<P>) => D,
d: (_: D, props: NoInfer<P>) => E, d: (_: D, props: NoInfer<P>) => E,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<E>>, Effect.Effect.Error<E>, Effect.Effect.Context<E>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<E>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -171,7 +171,7 @@ export namespace make {
d: (_: D, props: NoInfer<P>) => E, d: (_: D, props: NoInfer<P>) => E,
e: (_: E, props: NoInfer<P>) => F, e: (_: E, props: NoInfer<P>) => F,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<F>>, Effect.Effect.Error<F>, Effect.Effect.Context<F>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<F>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -187,7 +187,7 @@ export namespace make {
e: (_: E, props: NoInfer<P>) => F, e: (_: E, props: NoInfer<P>) => F,
f: (_: F, props: NoInfer<P>) => G, f: (_: F, props: NoInfer<P>) => G,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<G>>, Effect.Effect.Error<G>, Effect.Effect.Context<G>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<G>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -204,7 +204,7 @@ export namespace make {
f: (_: F, props: NoInfer<P>) => G, f: (_: F, props: NoInfer<P>) => G,
g: (_: G, props: NoInfer<P>) => H, g: (_: G, props: NoInfer<P>) => H,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<H>>, Effect.Effect.Error<H>, Effect.Effect.Context<H>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<H>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -222,7 +222,7 @@ export namespace make {
g: (_: G, props: NoInfer<P>) => H, g: (_: G, props: NoInfer<P>) => H,
h: (_: H, props: NoInfer<P>) => I, h: (_: H, props: NoInfer<P>) => I,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<I>>, Effect.Effect.Error<I>, Effect.Effect.Context<I>> ): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<I>>, 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 = never>( <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>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
_: Effect.Effect< _: Effect.Effect<
@@ -384,10 +384,10 @@ export const withOptions: {
)) ))
export const withRuntime: { export const withRuntime: {
<P, A extends React.ReactNode, E, R>( <P extends {}, A extends React.ReactNode, E, R>(
context: React.Context<Runtime.Runtime<R>>, context: React.Context<Runtime.Runtime<R>>,
): (self: Component<P, A, E, Types.NoInfer<R>>) => (props: P) => A ): (self: Component<P, A, E, Types.NoInfer<R>>) => (props: P) => A
<P, A extends React.ReactNode, E, R>( <P extends {}, A extends React.ReactNode, E, R>(
self: Component<P, A, E, Types.NoInfer<R>>, self: Component<P, A, E, Types.NoInfer<R>>,
context: React.Context<Runtime.Runtime<R>>, context: React.Context<Runtime.Runtime<R>>,
): (props: P) => A ): (props: P) => A

View File

@@ -22,7 +22,7 @@ export namespace Suspense {
const SuspenseProto = Object.freeze({ const SuspenseProto = Object.freeze({
[TypeId]: TypeId, [TypeId]: TypeId,
makeFunctionComponent<P, A extends React.ReactNode, E, R>( makeFunctionComponent<P extends {}, A extends React.ReactNode, E, R>(
this: Component.Component<P, A, 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,

View File

@@ -3,7 +3,7 @@ import { Flex, Text, TextField } from "@radix-ui/themes"
import { createFileRoute } from "@tanstack/react-router" import { createFileRoute } from "@tanstack/react-router"
import { GetRandomValues, makeUuid4 } from "@typed/id" import { GetRandomValues, makeUuid4 } from "@typed/id"
import { Effect } from "effect" import { Effect } from "effect"
import { Component, Memoized } from "effect-fc" import { Component, Memoized, Suspense } from "effect-fc"
import { Hooks } from "effect-fc/hooks" import { Hooks } from "effect-fc/hooks"
import * as React from "react" import * as React from "react"
@@ -64,8 +64,8 @@ class AsyncComponent extends Component.makeUntraced(function* AsyncComponent() {
</Flex> </Flex>
) )
}).pipe( }).pipe(
// Suspense.suspense, Suspense.suspense,
// Suspense.withOptions({ defaultFallback: <p>Loading...</p> }), Suspense.withOptions({ defaultFallback: <p>Loading...</p> }),
) {} ) {}
class MemoizedAsyncComponent extends Memoized.memo(AsyncComponent) {} class MemoizedAsyncComponent extends Memoized.memo(AsyncComponent) {}