diff --git a/packages/effect-fc/src/Async.ts b/packages/effect-fc/src/Async.ts index dae8184..ad458eb 100644 --- a/packages/effect-fc/src/Async.ts +++ b/packages/effect-fc/src/Async.ts @@ -1,5 +1,5 @@ /** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */ -import { Effect, Function, Predicate, Runtime, Scope } from "effect" +import { Effect, type Equivalence, Function, Predicate, Runtime, Scope } from "effect" import * as React from "react" import * as Component from "./Component.js" @@ -46,6 +46,30 @@ export const AsyncPrototype: AsyncPrototype = Object.freeze({ }, } as const) +export const defaultPropsEquivalence: Equivalence.Equivalence = ( + self: Record, + that: Record, +) => { + if (self === that) + return true + + for (const key in self) { + if (key === "fallback") + continue + if (!(key in that) || !Object.is(self[key], that[key])) + return false + } + + for (const key in that) { + if (key === "fallback") + continue + if (!(key in self)) + return false + } + + return true +} + export const isAsync = (u: unknown): u is Async => Predicate.hasProperty(u, AsyncTypeId) @@ -65,7 +89,7 @@ export const async = >( > & Async ) => Object.setPrototypeOf( - Object.assign(function() {}, self), + Object.assign(function() {}, self, { propsEquivalence: defaultPropsEquivalence }), Object.freeze(Object.setPrototypeOf( Object.assign({}, AsyncPrototype), Object.getPrototypeOf(self),