Comparing version 0.5.0 to 0.6.0
{ | ||
"name": "enmap", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -68,2 +68,24 @@ /** | ||
/** | ||
* Modify the property of a value inside the enmap, assuming this value is an object. | ||
* This is a shortcut to loading the key, changing the value, and setting it back. | ||
* @param {*} key Required. The key of the element to add to the EnMap object. | ||
* If the EnMap is persistent this value MUST be a string or number. | ||
* @param {*} prop Required. The property to modify inside the value object. | ||
* @param {*} val Required. The value to apply to the specified property. | ||
* @param {boolean} save Optional. Whether to save to persistent DB (used as false in init) | ||
* @return {Map} The EnMap object. | ||
*/ | ||
setProp(key, prop, val, save = true) { | ||
const data = super.get(key); | ||
if (typeof data !== 'object') { | ||
throw 'Method can only be used when the value is an object'; | ||
} | ||
data[prop] = val; | ||
if (this.persistent && save) { | ||
this.db.set(key, data); | ||
} | ||
return super.set(key, data); | ||
} | ||
/** | ||
* | ||
@@ -70,0 +92,0 @@ * @param {*} key Required. The key of the element to add to the EnMap object. |
59068
723