UNPKG

mediatr-ts

Version:

Mimic the famous MediatR csharp library see: (https://github.com/jbogard/MediatR)

65 lines 2.87 kB
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { OrderedMappings, byOrder } from "./orderedMappings.js"; /** * The PipelineBehaviorMappings class is a subclass of OrderedMappings that is used to manage a collection of * PipelineBehaviorData objects. * * @exports */ var PipelineBehaviorMappings = /** @class */ (function (_super) { __extends(PipelineBehaviorMappings, _super); function PipelineBehaviorMappings() { return _super !== null && _super.apply(this, arguments) || this; } /** * This method takes an array of PipelineBehaviorClass objects and sets the order of each item in the _internal_ collection * based on index in the array passed in. * * It takes a behaviour class as input and updates the order of each item in the the array based on its index. * If not found it place the order as -1. * * @param behaviorClasses The ordered list of pipeline behavior classes */ PipelineBehaviorMappings.prototype.setOrder = function (behaviorClasses) { var all = this.getAll(); for (var _i = 0, all_1 = all; _i < all_1.length; _i++) { var handler = all_1[_i]; handler.order = behaviorClasses.indexOf(handler.behaviorClass); } }; /** * This method returns a sorted array of all the items in the collection. * * @returns The array of handler classes in the order in which they should be executed. */ PipelineBehaviorMappings.prototype.getAll = function () { var items = __spreadArray([], this._mappings, true); return items.sort(byOrder); }; return PipelineBehaviorMappings; }(OrderedMappings)); export { PipelineBehaviorMappings }; //# sourceMappingURL=pipelineBehaviorMappings.js.map