FactuGES_ERP/packages/rdx-ddd/src/value-objects/value-object.ts
2025-09-04 12:02:24 +02:00

26 lines
555 B
TypeScript

import { shallowEqual } from "shallow-equal-object";
export abstract class ValueObject<T> {
protected readonly props: T;
protected constructor(props: T) {
this.props = Object.freeze(props); // 🔒 Garantiza inmutabilidad
}
abstract getProps(): any;
abstract toPrimitive(): any;
equals(other: ValueObject<T>): boolean {
if (!(other instanceof ValueObject)) {
return false;
}
if (other.props === undefined || other.props === null) {
return false;
}
return shallowEqual(this.props, other.props);
}
}