Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/form-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ export function evaluate<T>(objA: T, objB: T) {
return objA.getTime() === objB.getTime()
}

if (
typeof (objA as any).equals === 'function' &&
objA.constructor === objB.constructor
) {
return (objA as any).equals(objB)
}

if (objA instanceof Map && objB instanceof Map) {
if (objA.size !== objB.size) return false
for (const [k, v] of objA) {
Expand Down
12 changes: 12 additions & 0 deletions packages/form-core/tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,18 @@ describe('evaluate', () => {
expect(dateObjectFalse).toEqual(false)
})

it('should test equality for objects with an equals() method (e.g. Temporal, Decimal.js)', () => {
class ValueType {
constructor(private val: number) {}
equals(other: ValueType) {
return this.val === other.val
}
}

expect(evaluate(new ValueType(1), new ValueType(1))).toEqual(true)
expect(evaluate(new ValueType(1), new ValueType(2))).toEqual(false)
})

it('should test equality between Map objects', () => {
const map1 = new Map([
['a', 1],
Expand Down