storage.js: Properly handle if keys are entirely removed

This commit is contained in:
Johannes Meyer 2019-07-10 07:51:48 +02:00
parent 363486277b
commit 8937e11a09

View File

@ -251,17 +251,20 @@
* Update the map * Update the map
* *
* @param {object} newValue * @param {object} newValue
* @param {object} oldValue
*/ */
onChange: function(newValue, oldValue) { onChange: function(newValue) {
// Check for deletions first. Uses keys() to iterate over a copy // Check for deletions first. Uses keys() to iterate over a copy
this.keys().forEach(function (key) { this.keys().forEach(function (key) {
if (typeof newValue[key] === 'undefined') { if (newValue === null || typeof newValue[key] === 'undefined') {
this.data.delete(key); this.data.delete(key);
$(window).trigger('StorageAwareMapDelete', key); $(window).trigger('StorageAwareMapDelete', key);
} }
}, this); }, this);
if (newValue === null) {
return;
}
// Now check for new entries // Now check for new entries
Object.keys(newValue).forEach(function(key) { Object.keys(newValue).forEach(function(key) {
var known = this.data.has(key); var known = this.data.has(key);