Explorar o código

Account for old value with watcher

Caleb Porzio %!s(int64=4) %!d(string=hai) anos
pai
achega
88f463b60e
Modificáronse 1 ficheiros con 5 adicións e 3 borrados
  1. 5 3
      packages/alpinejs/src/magics/$watch.js

+ 5 - 3
packages/alpinejs/src/magics/$watch.js

@@ -17,10 +17,12 @@ magic('watch', el => (key, callback) => {
         if (! firstTime) {
             // We have to queue this watcher as a microtask so that
             // the watcher doesn't pick up its own dependancies.
-            queueMicrotask(() => callback(value, oldValue))
-        }
+            queueMicrotask(() => {
+                callback(value, oldValue)
 
-        oldValue = value
+                oldValue = value
+            })
+        }
 
         firstTime = false
     }))