UNPKG

@splitsoftware/splitio-commons

Version:
68 lines (67 loc) 2.16 kB
import { objectAssign } from '../../utils/lang/objectAssign'; var AttributesCacheInMemory = /** @class */ (function () { function AttributesCacheInMemory() { this.attributesCache = {}; } /** * Create or update the value for the given attribute * * @param attributeName - attribute name * @param attributeValue - attribute value * @returns the attribute was stored */ AttributesCacheInMemory.prototype.setAttribute = function (attributeName, attributeValue) { this.attributesCache[attributeName] = attributeValue; return true; }; /** * Retrieves the value of a given attribute * * @param attributeName - attribute name * @returns stored attribute value */ AttributesCacheInMemory.prototype.getAttribute = function (attributeName) { return this.attributesCache[attributeName]; }; /** * Create or update all the given attributes * * @param attributes - attributes to create or update * @returns attributes were stored */ AttributesCacheInMemory.prototype.setAttributes = function (attributes) { this.attributesCache = objectAssign(this.attributesCache, attributes); return true; }; /** * Retrieve the full attributes map * * @returns stored attributes */ AttributesCacheInMemory.prototype.getAll = function () { return this.attributesCache; }; /** * Removes a given attribute from the map * * @param attributeName - attribute to remove * @returns attribute removed */ AttributesCacheInMemory.prototype.removeAttribute = function (attributeName) { if (Object.keys(this.attributesCache).indexOf(attributeName) >= 0) { delete this.attributesCache[attributeName]; return true; } return false; }; /** * Clears all attributes stored in the SDK * */ AttributesCacheInMemory.prototype.clear = function () { this.attributesCache = {}; return true; }; return AttributesCacheInMemory; }()); export { AttributesCacheInMemory };