/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */ import { type Equivalence, Function, Predicate } from "effect" import * as React from "react" import type * as Component from "./Component.js" export const TypeId: unique symbol = Symbol.for("@effect-fc/Memoized/Memoized") export type TypeId = typeof TypeId export interface Memoized

extends MemoizedOptions

{ readonly [TypeId]: TypeId } export interface MemoizedOptions

{ readonly propsEquivalence?: Equivalence.Equivalence

} export const MemoizedPrototype = Object.freeze({ [TypeId]: TypeId, transformFunctionComponent

( this: Memoized

, f: React.FC

, ) { return React.memo(f, this.propsEquivalence) }, } as const) export const isMemoized = (u: unknown): u is Memoized => Predicate.hasProperty(u, TypeId) export const memoized = >( self: T ): T & Memoized> => Object.setPrototypeOf( Object.assign(function() {}, self), Object.freeze(Object.setPrototypeOf( Object.assign({}, MemoizedPrototype), Object.getPrototypeOf(self), )), ) export const withOptions: { & Memoized>( options: Partial>> ): (self: T) => T & Memoized>( self: T, options: Partial>>, ): T } = Function.dual(2, & Memoized>( self: T, options: Partial>>, ): T => Object.setPrototypeOf( Object.assign(function() {}, self, options), Object.getPrototypeOf(self), ))