mediatr-ts
Version:
Mimic the famous MediatR csharp library see: (https://github.com/jbogard/MediatR)
53 lines • 1.48 kB
JavaScript
/**
* 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;
}());
export { OrderedMappings };
/**
* Used to comapre elements in an ordered mapping
*
* @exports
*
* @param a The first element
* @param b The second element
* @returns The comparison result
*/
export function byOrder(a, b) {
return (b.order || 0) - (a.order || 0);
}
//# sourceMappingURL=orderedMappings.js.map