2021-10-14 15:56:37 +03:00
|
|
|
const {isEqual} = require('lodash');
|
|
|
|
|
2021-10-07 17:42:56 +03:00
|
|
|
/**
|
|
|
|
* @template T
|
|
|
|
*/
|
|
|
|
class ValueObject {
|
|
|
|
/** @type {{value: T}} */
|
|
|
|
props
|
|
|
|
|
|
|
|
/** @type T */
|
|
|
|
get value() {
|
|
|
|
return this.props.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
* @param {T} value
|
|
|
|
*/
|
|
|
|
constructor(value) {
|
|
|
|
/** @private */
|
|
|
|
this.props = {value};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {any} other
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
equals(other) {
|
|
|
|
if (this === other) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (other instanceof ValueObject) {
|
2021-10-14 15:56:37 +03:00
|
|
|
if (isEqual(this.props.value, other.props.value)) {
|
2021-10-07 17:42:56 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ValueObject;
|