@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
109 lines • 4.39 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var operators_1 = require("rxjs/operators");
var emission_1 = __importDefault(require("../shared/emission"));
var emission_error_1 = require("../shared/errors/emission-error");
var pin_1 = __importDefault(require("../pin/pin"));
var group_1 = __importDefault(require("../pin/group"));
var source_1 = __importDefault(require("../pin/source"));
var pipe_1 = __importDefault(require("../pin/pipe"));
var filter_1 = require("../pin/filter");
var agent_1 = require("./agent");
/**
*
* Represents [handle error](https://connective.dev/docs/handle-error) agents.
*
*/
var HandleError = /** @class */ (function (_super) {
__extends(HandleError, _super);
function HandleError() {
var _this = _super.call(this, {
inputs: ['input'],
outputs: ['output', 'error'],
}) || this;
_this._err = source_1.default();
_this._gate = _this.input.to(pipe_1.default(operators_1.tap(null, function (error) {
if (emission_error_1.isEmissionError(error))
_this._err.emit(emission_1.default(error, error.emission.context));
else
_this._err.send(error);
}), operators_1.retry(), operators_1.share()));
return _this;
}
HandleError.prototype.createOutput = function (label) {
this.checkOutput(label);
if (label == 'error')
return group_1.default(this._err, this._gate.to(filter_1.block())).to(pin_1.default());
else
return this._gate;
};
HandleError.prototype.createEntries = function () { return [this.input]; };
HandleError.prototype.createExits = function () { return [this.output, this.error]; };
HandleError.prototype.clear = function () {
this._err.clear();
return _super.prototype.clear.call(this);
};
Object.defineProperty(HandleError.prototype, "input", {
/**
*
* Shortcut for `.in('input')`, the input pin receiving values.
* [Read this](https://connective.dev/docs/handle-error#signature) for more details.
*
*/
get: function () { return this.in('input'); },
enumerable: true,
configurable: true
});
Object.defineProperty(HandleError.prototype, "output", {
/**
*
* Shortcut for `.out('output')`, which will emit error-free values.
* [Read this](https://connective.dev/docs/handle-error#signature) for more details.
*
*/
get: function () { return this.out('output'); },
enumerable: true,
configurable: true
});
Object.defineProperty(HandleError.prototype, "error", {
/**
*
* Shortcut for `.out('error')`, which will emit errors.
* [Read this](https://connective.dev/docs/handle-error#signature) for more details.
*
*/
get: function () { return this.out('error'); },
enumerable: true,
configurable: true
});
return HandleError;
}(agent_1.Agent));
exports.HandleError = HandleError;
/**
*
* Creates a [handle error](https://connective.dev/docs/handle-error) agent.
* Handle error agents will pass on incoming values, but also will catch errors
* occuring upstream and pass them along, stopping the flow from closing in resposne to such errors.
* [Checkout the docs](https://connective.dev/docs/handle-error) for examples and further information.
*
*/
function handleError() { return new HandleError(); }
exports.handleError = handleError;
exports.default = handleError;
//# sourceMappingURL=handle-error.js.map