FactuGES_ERP/apps/server/src/common/domain/value-objects/value-object.ts

24 lines
523 B
TypeScript
Raw Normal View History

2025-01-29 19:02:59 +00:00
import { shallowEqual } from "shallow-equal-object";
export abstract class ValueObject<T> {
2025-02-20 18:55:24 +00:00
protected readonly props: T;
2025-01-29 19:02:59 +00:00
2025-02-20 18:55:24 +00:00
protected constructor(props: T) {
this.props = Object.freeze(props); // 🔒 Garantiza inmutabilidad
2025-01-29 19:02:59 +00:00
}
2025-02-20 18:55:24 +00:00
abstract getValue(): any;
2025-01-29 19:02:59 +00:00
equals(other: ValueObject<T>): boolean {
if (!(other instanceof ValueObject)) {
return false;
}
2025-02-20 18:55:24 +00:00
if (other.props === undefined || other.props === null) {
2025-01-29 19:02:59 +00:00
return false;
}
2025-02-20 18:55:24 +00:00
return shallowEqual(this.props, other.props);
2025-01-29 19:02:59 +00:00
}
}