mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
c2f85d3742
no-issue This ensures that ValueObjects can contain non-primitive types.
44 lines
719 B
JavaScript
44 lines
719 B
JavaScript
const {isEqual} = require('lodash');
|
|
|
|
/**
|
|
* @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) {
|
|
if (isEqual(this.props.value, other.props.value)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
module.exports = ValueObject;
|