A social knowledge tool for researchers built on ATProto
1import { UniqueEntityID } from './UniqueEntityID';
2
3const isEntity = (v: any): v is Entity<any> => {
4 return v instanceof Entity;
5};
6
7export abstract class Entity<T> {
8 protected readonly _id: UniqueEntityID;
9 public readonly props: T;
10
11 constructor(props: T, id?: UniqueEntityID) {
12 this._id = id ? id : new UniqueEntityID();
13 this.props = props;
14 }
15
16 public equals(object?: Entity<T>): boolean {
17 if (object == null || object == undefined) {
18 return false;
19 }
20
21 if (this === object) {
22 return true;
23 }
24
25 if (!isEntity(object)) {
26 return false;
27 }
28
29 return this._id.equals(object._id);
30 }
31}