0.1.0 #1

Merged
Thilawyn merged 81 commits from next into master 2025-07-17 21:17:57 +02:00
2 changed files with 15 additions and 8 deletions
Showing only changes of commit 1317baf7ac - Show all commits

View File

@@ -1,4 +1,4 @@
import { Context, Effect, type Equivalence, type ExecutionStrategy, Function, pipe, Pipeable, Predicate, Runtime, Scope, String, Tracer, type Utils } from "effect" import { Context, Effect, type Equivalence, ExecutionStrategy, Function, pipe, Pipeable, Predicate, Runtime, Scope, String, Tracer, type Utils } from "effect"
import * as React from "react" import * as React from "react"
import * as Hook from "./Hook.js" import * as Hook from "./Hook.js"
import type { ExcludeKeys } from "./utils.js" import type { ExcludeKeys } from "./utils.js"
@@ -26,6 +26,11 @@ const ComponentProto = Object.seal({
pipe() { return Pipeable.pipeArguments(this, arguments) } pipe() { return Pipeable.pipeArguments(this, arguments) }
} as const) } as const)
const defaultOptions: Component.Options = {
finalizerExecutionMode: "sync",
finalizerExecutionStrategy: ExecutionStrategy.sequential,
}
const nonReactiveTags = [Tracer.ParentSpan] as const const nonReactiveTags = [Tracer.ParentSpan] as const
@@ -190,7 +195,7 @@ export const make: (
? Effect.fn(displayName)(spanNameOrBody as any, ...pipeables as []) ? Effect.fn(displayName)(spanNameOrBody as any, ...pipeables as [])
: Effect.fn(spanNameOrBody as any, ...pipeables), : Effect.fn(spanNameOrBody as any, ...pipeables),
displayName, displayName,
options: {}, options: { ...defaultOptions },
}, ComponentProto) }, ComponentProto)
} }
else { else {
@@ -198,7 +203,7 @@ export const make: (
return (body: any, ...pipeables: any[]) => Object.setPrototypeOf({ return (body: any, ...pipeables: any[]) => Object.setPrototypeOf({
body: Effect.fn(spanNameOrBody, spanOptions)(body, ...pipeables as []), body: Effect.fn(spanNameOrBody, spanOptions)(body, ...pipeables as []),
displayName: displayNameFromBody(body) ?? spanNameOrBody, displayName: displayNameFromBody(body) ?? spanNameOrBody,
options: {}, options: { ...defaultOptions },
}, ComponentProto) }, ComponentProto)
} }
} }
@@ -206,7 +211,7 @@ export const make: (
export const makeUntraced: make.Gen = (body: Function, ...pipeables: any[]) => Object.setPrototypeOf({ export const makeUntraced: make.Gen = (body: Function, ...pipeables: any[]) => Object.setPrototypeOf({
body: Effect.fnUntraced(body as any, ...pipeables as []), body: Effect.fnUntraced(body as any, ...pipeables as []),
displayName: displayNameFromBody(body), displayName: displayNameFromBody(body),
options: {}, options: { ...defaultOptions },
}, ComponentProto) }, ComponentProto)
const displayNameFromBody = (body: Function) => !String.isEmpty(body.name) ? body.name : undefined const displayNameFromBody = (body: Function) => !String.isEmpty(body.name) ? body.name : undefined
@@ -230,15 +235,15 @@ export const withDisplayName: {
export const withOptions: { export const withOptions: {
<T extends Component<any, any, any>>( <T extends Component<any, any, any>>(
options: Component.Options options: Partial<Component.Options>
): (self: T) => T ): (self: T) => T
<T extends Component<any, any, any>>( <T extends Component<any, any, any>>(
self: T, self: T,
options: Component.Options, options: Partial<Component.Options>,
): T ): T
} = Function.dual(2, <T extends Component<any, any, any>>( } = Function.dual(2, <T extends Component<any, any, any>>(
self: T, self: T,
options: Component.Options, options: Partial<Component.Options>,
): T => Object.setPrototypeOf( ): T => Object.setPrototypeOf(
{ ...self, options: { ...self.options, ...options } }, { ...self, options: { ...self.options, ...options } },
Object.getPrototypeOf(self), Object.getPrototypeOf(self),

View File

@@ -110,4 +110,6 @@ export const Todo = Component.make(function* Todo(props: TodoProps) {
} }
</Flex> </Flex>
) )
}) }).pipe(
Component.memo
)