Skip to content

Commit

Permalink
Add value object shared class
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejkang committed Sep 1, 2021
1 parent d04c99b commit 2983a80
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/shared/core/ValueObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interface ValueObjectProps {
[index: string]: any;
}

export abstract class ValueObject<T extends ValueObjectProps> {
public props: T;

protected constructor(props: T) {
this.props = { ...props };
}

public equals(valueObject?: ValueObject<T>): boolean {
if (valueObject === null || valueObject === undefined) {
return false;
}

if (valueObject.props === undefined) {
return false;
}

return JSON.stringify(this.props) === JSON.stringify(valueObject.props);
}
}

0 comments on commit 2983a80

Please sign in to comment.