4lessandrodev / rich-domain

A lib to help you create a robust project based on domain driven-design (ddd) principles with typescript and zero dependencies.
https://www.npmjs.com/package/rich-domain
MIT License
122 stars 5 forks source link

Feat/equal #28

Closed 4lessandrodev closed 1 year ago

4lessandrodev commented 1 year ago

1.16.0 - 2022-01-12

Added

27

Example


// entity
class EntityExample extends Entity<Props>{
    private constructor(props: Props) {
        super(props)
    }

    public static create(props: Props): Result<EntityExample> {
        return Ok(new EntityExample(props));
    }
}

const a = EntityExample.create({...props, id }).value();
const b = EntityExample.create({...props, id}).value();

console.log(a.isEqual(b));

> true

// ----------------

// value object
class Exam extends ValueObject<Props> {
    private constructor(props: Props){
        super(props)
    }

    public static create(props: Props): Result<Exam> {
        return Ok(new Exam(props));
    }
};

const a = Exam.create({ value : "hello there" }).value();
const b = Exam.create({ value : "hello there" }).value();

console.log(a.isEqual(b));

> true