tsbase
Version:
Base class libraries for TypeScript
44 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Result = void 0;
/**
* An abstraction of the result of an action or command -
* Use this pattern to return meaningful results from operations
* that may have otherwise been void.
*/
class Result {
/**
* Indicates whether or not the action returning the result was successful -
* The lack of errors indicates success. The presence of errors indicates failure.
*/
get IsSuccess() {
return this.ErrorMessages.length === 0;
}
constructor(Value) {
this.Value = Value;
/**
* Messages indicating why the action returning the result was not successful
*/
this.ErrorMessages = Array();
}
/**
* Returns a new result containing errors from this result instance as well as the one passed
* @param result
*/
CombineWith(result) {
const newResult = new Result();
newResult.ErrorMessages = this.ErrorMessages.concat(result.ErrorMessages);
return newResult;
}
/**
* Adds an error to ErrorMessages only when that error is not already present in the collection
* @param error
*/
AddError(error) {
if (!this.ErrorMessages.includes(error)) {
this.ErrorMessages.push(error);
}
}
}
exports.Result = Result;
//# sourceMappingURL=Result.js.map