UNPKG

@rimbu/proximity

Version:

Immutable ProximityMap implementation for TypeScript

109 lines 4.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProximityMapBuilder = void 0; var wrapping_cjs_1 = require("./wrapping.cjs"); var ProximityMapBuilder = /** @class */ (function () { function ProximityMapBuilder(context, source) { var _this = this; this.context = context; this.source = source; /** * Applying `get()` to the Builder does NOT apply the proximity algorithm - which would * be pointless at this construction stage; the internal, hash-based builder * is queried instead * */ this.get = function (key, otherwise) { if (undefined !== _this.source) return _this.source.get(key, otherwise); return _this.internalBuilder.get(key, otherwise); }; // prettier-ignore this.hasKey = function (key) { return _this.internalBuilder.hasKey(key); }; this.forEach = function (f, options) { if (options === void 0) { options = {}; } _this.internalBuilder.forEach(f, options); }; this.addEntry = function (entry) { var hasChanged = _this.internalBuilder.addEntry(entry); if (hasChanged) { _this.source = undefined; } return hasChanged; }; this.addEntries = function (entries) { var hasChanged = _this.internalBuilder.addEntries(entries); if (hasChanged) { _this.source = undefined; } return hasChanged; }; this.set = function (key, value) { var hasChanged = _this.internalBuilder.set(key, value); if (hasChanged) { _this.source = undefined; } return hasChanged; }; this.removeKey = function (key, otherwise) { if (_this.internalBuilder.hasKey(key)) { _this.source = undefined; } return _this.internalBuilder.removeKey(key, otherwise); }; // prettier-ignore this.removeKeys = function (keys) { var hasChanged = _this.internalBuilder.removeKeys(keys); if (hasChanged) { _this.source = undefined; } return hasChanged; }; this.modifyAt = function (key, options) { var hasChanged = _this.internalBuilder.modifyAt(key, options); if (hasChanged) { _this.source = undefined; } return hasChanged; }; // prettier-ignore this.updateAt = function (key, update, otherwise) { var previousValue = _this.internalBuilder.updateAt(key, update, otherwise); var newValue = _this.internalBuilder.get(key); if (!Object.is(previousValue, newValue)) { _this.source = undefined; } return previousValue; }; this.build = function () { return _this.source !== undefined ? _this.source : (0, wrapping_cjs_1.wrapHashMap)(_this.context, _this.internalBuilder.build()); }; // prettier-ignore this.buildMapValues = function (mapFun) { return (0, wrapping_cjs_1.wrapHashMap)(_this.context, _this.internalBuilder.buildMapValues(mapFun)); }; this.internalBuilder = context.hashMapContext.builder(); this.internalBuilder.addEntries(source); } Object.defineProperty(ProximityMapBuilder.prototype, "size", { get: function () { return this.internalBuilder.size; }, enumerable: false, configurable: true }); Object.defineProperty(ProximityMapBuilder.prototype, "isEmpty", { get: function () { return this.internalBuilder.isEmpty; }, enumerable: false, configurable: true }); return ProximityMapBuilder; }()); exports.ProximityMapBuilder = ProximityMapBuilder; //# sourceMappingURL=builder.cjs.map