Caleb Porzio 2 年之前
父節點
當前提交
f3616c8706
共有 1 個文件被更改,包括 13 次插入2 次删除
  1. 13 2
      packages/alpinejs/src/directives/x-modelable.js

+ 13 - 2
packages/alpinejs/src/directives/x-modelable.js

@@ -22,7 +22,18 @@ directive('modelable', (el, { expression }, { effect, evaluateLater }) => {
         let outerGet = el._x_model.get
         let outerSet = el._x_model.set
 
-        effect(() => innerSet(outerGet()))
-        effect(() => outerSet(innerGet()))
+        effect(() => {
+            // Putting this operation in a microtask so that
+            // it doesn't get tracked in the effect:
+            let value = outerGet()
+            queueMicrotask(() => innerSet(value))
+        })
+
+        effect(() => {
+            // Putting this operation in a microtask so that
+            // it doesn't get tracked in the effect:
+            let value = innerGet()
+            queueMicrotask(() => outerSet(value))
+        })
     })
 })