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
1 changed files with 6 additions and 3 deletions

View File

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