tsbase
Version:
Base class libraries for TypeScript
49 lines • 1.67 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.
*/
var Result = /** @class */ (function () {
function Result(Value) {
this.Value = Value;
/**
* Messages indicating why the action returning the result was not successful
*/
this.ErrorMessages = Array();
}
Object.defineProperty(Result.prototype, "IsSuccess", {
/**
* Indicates whether or not the action returning the result was successful -
* The lack of errors indicates success. The presence of errors indicates failure.
*/
get: function () {
return this.ErrorMessages.length === 0;
},
enumerable: false,
configurable: true
});
/**
* Returns a new result containing errors from this result instance as well as the one passed
* @param result
*/
Result.prototype.CombineWith = function (result) {
var 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
*/
Result.prototype.AddError = function (error) {
if (this.ErrorMessages.indexOf(error) === -1) {
this.ErrorMessages.push(error);
}
};
return Result;
}());
exports.Result = Result;
//# sourceMappingURL=Result.js.map