0.1.4 #5

Merged
Thilawyn merged 67 commits from next into master 2025-10-02 18:18:23 +02:00
2 changed files with 16 additions and 16 deletions
Showing only changes of commit bad8690156 - Show all commits

View File

@@ -3,14 +3,14 @@ import * as React from "react"
import type * as Component from "./Component.js" import type * as Component from "./Component.js"
export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense") export const TypeId: unique symbol = Symbol.for("effect-fc/Async")
export type TypeId = typeof TypeId export type TypeId = typeof TypeId
export interface Suspense extends Suspense.Options { export interface Async extends Async.Options {
readonly [TypeId]: TypeId readonly [TypeId]: TypeId
} }
export namespace Suspense { export namespace Async {
export interface Options { export interface Options {
readonly defaultFallback?: React.ReactNode readonly defaultFallback?: React.ReactNode
} }
@@ -23,13 +23,13 @@ const SuspenseProto = Object.freeze({
[TypeId]: TypeId, [TypeId]: TypeId,
makeFunctionComponent<P extends {}, 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> & Async,
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>, runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
scope: Scope.Scope, scope: Scope.Scope,
) { ) {
const SuspenseInner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise) const SuspenseInner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise)
return ({ fallback, name, ...props }: Suspense.Props) => { return ({ fallback, name, ...props }: Async.Props) => {
const promise = Runtime.runPromise(runtimeRef.current)( const promise = Runtime.runPromise(runtimeRef.current)(
Effect.provideService(this.body(props as P), Scope.Scope, scope) Effect.provideService(this.body(props as P), Scope.Scope, scope)
) )
@@ -44,19 +44,19 @@ const SuspenseProto = Object.freeze({
} as const) } as const)
export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId) export const isAsync = (u: unknown): u is Async => Predicate.hasProperty(u, TypeId)
export const suspense = <T extends Component.Component<any, any, any, any>>( export const async = <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.Props<T> & Suspense.Props, Component.Component.Props<T> & Async.Props,
Component.Component.Success<T>, Component.Component.Success<T>,
Component.Component.Error<T>, Component.Component.Error<T>,
Component.Component.Context<T> Component.Component.Context<T>
> >
& Suspense & Async
) => Object.setPrototypeOf( ) => Object.setPrototypeOf(
Object.assign(function() {}, self), Object.assign(function() {}, self),
Object.freeze(Object.setPrototypeOf( Object.freeze(Object.setPrototypeOf(
@@ -66,16 +66,16 @@ export const suspense = <T extends Component.Component<any, any, any, any>>(
) )
export const withOptions: { export const withOptions: {
<T extends Component.Component<any, any, any, any> & Suspense>( <T extends Component.Component<any, any, any, any> & Async>(
options: Partial<Suspense.Options> options: Partial<Async.Options>
): (self: T) => T ): (self: T) => T
<T extends Component.Component<any, any, any, any> & Suspense>( <T extends Component.Component<any, any, any, any> & Async>(
self: T, self: T,
options: Partial<Suspense.Options>, options: Partial<Async.Options>,
): T ): T
} = Function.dual(2, <T extends Component.Component<any, any, any, any> & Suspense>( } = Function.dual(2, <T extends Component.Component<any, any, any, any> & Async>(
self: T, self: T,
options: Partial<Suspense.Options>, options: Partial<Async.Options>,
): T => Object.setPrototypeOf( ): T => Object.setPrototypeOf(
Object.assign(function() {}, self, options), Object.assign(function() {}, self, options),
Object.getPrototypeOf(self), Object.getPrototypeOf(self),

View File

@@ -1,5 +1,5 @@
export * as Async from "./Async.js"
export * as Component from "./Component.js" export * as Component from "./Component.js"
export * as Form from "./Form.js" export * as Form from "./Form.js"
export * as Memoized from "./Memoized.js" export * as Memoized from "./Memoized.js"
export * as ReactRuntime from "./ReactRuntime.js" export * as ReactRuntime from "./ReactRuntime.js"
export * as Suspense from "./Suspense.js"