diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index d502588..a341e49 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -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 Hook from "./Hook.js" import type { ExcludeKeys } from "./utils.js" @@ -26,6 +26,11 @@ const ComponentProto = Object.seal({ pipe() { return Pipeable.pipeArguments(this, arguments) } } as const) +const defaultOptions: Component.Options = { + finalizerExecutionMode: "sync", + finalizerExecutionStrategy: ExecutionStrategy.sequential, +} + const nonReactiveTags = [Tracer.ParentSpan] as const @@ -190,7 +195,7 @@ export const make: ( ? Effect.fn(displayName)(spanNameOrBody as any, ...pipeables as []) : Effect.fn(spanNameOrBody as any, ...pipeables), displayName, - options: {}, + options: { ...defaultOptions }, }, ComponentProto) } else { @@ -198,7 +203,7 @@ export const make: ( return (body: any, ...pipeables: any[]) => Object.setPrototypeOf({ body: Effect.fn(spanNameOrBody, spanOptions)(body, ...pipeables as []), displayName: displayNameFromBody(body) ?? spanNameOrBody, - options: {}, + options: { ...defaultOptions }, }, ComponentProto) } } @@ -206,7 +211,7 @@ export const make: ( export const makeUntraced: make.Gen = (body: Function, ...pipeables: any[]) => Object.setPrototypeOf({ body: Effect.fnUntraced(body as any, ...pipeables as []), displayName: displayNameFromBody(body), - options: {}, + options: { ...defaultOptions }, }, ComponentProto) const displayNameFromBody = (body: Function) => !String.isEmpty(body.name) ? body.name : undefined @@ -230,15 +235,15 @@ export const withDisplayName: { export const withOptions: { >( - options: Component.Options + options: Partial ): (self: T) => T >( self: T, - options: Component.Options, + options: Partial, ): T } = Function.dual(2, >( self: T, - options: Component.Options, + options: Partial, ): T => Object.setPrototypeOf( { ...self, options: { ...self.options, ...options } }, Object.getPrototypeOf(self), diff --git a/packages/example/src/todo/Todo.tsx b/packages/example/src/todo/Todo.tsx index 7767e32..3c8365a 100644 --- a/packages/example/src/todo/Todo.tsx +++ b/packages/example/src/todo/Todo.tsx @@ -110,4 +110,6 @@ export const Todo = Component.make(function* Todo(props: TodoProps) { } ) -}) +}).pipe( + Component.memo +)