UNPKG

mediatr-ts

Version:

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

57 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.byOrder = exports.OrderedMappings = void 0; /** * OrderedMappings is an abstract class that manages a collection of ordered mappings, * where each mapping has a specific order and associated data. * * @exports */ var OrderedMappings = /** @class */ (function () { function OrderedMappings() { this._mappings = []; } /** * Adds a new mapping to the collection, automatically assigning an order if not provided ( defaults to the next available index). * @param mapping */ OrderedMappings.prototype.add = function (mapping) { if (mapping.order !== 0) { mapping.order = this._mappings.length; } this._mappings.push(mapping); }; /** * Resets the collection by removing all existing mappings. */ OrderedMappings.prototype.clear = function () { this._mappings = []; }; Object.defineProperty(OrderedMappings.prototype, "length", { /** * The mappings length * @returns The length */ get: function () { return this._mappings.length; }, enumerable: false, configurable: true }); return OrderedMappings; }()); exports.OrderedMappings = OrderedMappings; /** * Used to comapre elements in an ordered mapping * * @exports * * @param a The first element * @param b The second element * @returns The comparison result */ function byOrder(a, b) { return (b.order || 0) - (a.order || 0); } exports.byOrder = byOrder; //# sourceMappingURL=orderedMappings.js.map