Kaynağa Gözat

fix: update value store before notifying change

tophf 3 yıl önce
ebeveyn
işleme
a5ab9bb7c4
1 değiştirilmiş dosya ile 7 ekleme ve 10 silme
  1. 7 10
      src/injected/web/gm-values.js

+ 7 - 10
src/injected/web/gm-values.js

@@ -20,7 +20,7 @@ bridge.addHandlers({
         const update = updates[id];
         const keyHooks = changeHooks[id];
         if (keyHooks) changedRemotely(keyHooks, oldData, update);
-        if (partial) applyPartialUpdate(oldData, update);
+        else if (partial) applyPartialUpdate(oldData, update);
         else store.values[id] = update;
       }
     });
@@ -61,15 +61,12 @@ function applyPartialUpdate(data, update) {
 
 function changedRemotely(keyHooks, data, update) {
   objectKeys(update)::forEach(key => {
-    const hooks = keyHooks[key];
-    if (hooks) {
-      let raw = update[key];
-      if (!raw) raw = undefined; // partial `update` currently uses null for deleted values
-      const oldRaw = data[key];
-      if (oldRaw !== raw) {
-        data[key] = raw; // will be deleted later in applyPartialUpdate if empty
-        notifyChange(hooks, key, undefined, raw, oldRaw, true);
-      }
+    const raw = update[key] || undefined; // partial `update` currently uses null for deleted values
+    const oldRaw = data[key];
+    if (oldRaw !== raw) {
+      if (raw) data[key] = raw; else delete data[key];
+      const hooks = keyHooks[key];
+      if (hooks) notifyChange(hooks, key, undefined, raw, oldRaw, true);
     }
   });
 }