Explorar o código

added 'once' back

Muzaffer Dede %!s(int64=5) %!d(string=hai) anos
pai
achega
7cb0bb10e5
Modificáronse 3 ficheiros con 50 adicións e 42 borrados
  1. 16 15
      dist/alpine-ie11.js
  2. 16 13
      dist/alpine.js
  3. 18 14
      src/utils.js

+ 16 - 15
dist/alpine-ie11.js

@@ -5924,7 +5924,7 @@
 
         stages.end(); // Asign current transition to el in case we need to force it
 
-        el.__x_transition_remaining = function () {
+        el.__x_transition_remaining = once(function () {
           _newArrowCheck(this, _this15);
 
           stages.hide(); // Adding an "isConnected" check, in case the callback
@@ -5936,26 +5936,27 @@
 
 
           delete el.__x_transition_remaining;
-
-          if (el.__x_transition_timer) {
-            clearTimeout(el.__x_transition_timer);
-          }
-        }.bind(this);
-
-        el.__x_transition_timer = setTimeout(function () {
-          _newArrowCheck(this, _this15);
-
-          // We only want to run remaining transitions in the end if they exists
-          if (el.__x_transition_remaining) {
-            el.__x_transition_remaining();
-          }
-        }.bind(this), duration);
+        }.bind(this));
+        setTimeout(el.__x_transition_remaining, duration);
       }.bind(this));
     }.bind(this));
   }
   function isNumeric(subject) {
     return !isNaN(subject);
   }
+  /**
+   * Ensure a function is called only once.
+   */
+
+  function once(fn) {
+    var called = false;
+    return function () {
+      if (!called) {
+        called = true;
+        fn.apply(this, arguments);
+      }
+    };
+  }
 
   function handleForDirective(component, templateEl, expression, initialUpdate, extraVars) {
     var _this = this;

+ 16 - 13
dist/alpine.js

@@ -407,7 +407,7 @@
       requestAnimationFrame(() => {
         stages.end(); // Asign current transition to el in case we need to force it
 
-        el.__x_transition_remaining = () => {
+        el.__x_transition_remaining = once(() => {
           stages.hide(); // Adding an "isConnected" check, in case the callback
           // removed the element from the DOM.
 
@@ -417,24 +417,27 @@
 
 
           delete el.__x_transition_remaining;
-
-          if (el.__x_transition_timer) {
-            clearTimeout(el.__x_transition_timer);
-          }
-        };
-
-        el.__x_transition_timer = setTimeout(() => {
-          // We only want to run remaining transitions in the end if they exists
-          if (el.__x_transition_remaining) {
-            el.__x_transition_remaining();
-          }
-        }, duration);
+        });
+        setTimeout(el.__x_transition_remaining, duration);
       });
     });
   }
   function isNumeric(subject) {
     return !isNaN(subject);
   }
+  /**
+   * Ensure a function is called only once.
+   */
+
+  function once(fn) {
+    let called = false;
+    return function () {
+      if (!called) {
+        called = true;
+        fn.apply(this, arguments);
+      }
+    };
+  }
 
   function handleForDirective(component, templateEl, expression, initialUpdate, extraVars) {
     warnIfNotTemplateTag(templateEl);

+ 18 - 14
src/utils.js

@@ -399,8 +399,7 @@ export function transition(el, stages) {
             stages.end()
 
             // Asign current transition to el in case we need to force it
-            el.__x_transition_remaining =() => {
-
+            el.__x_transition_remaining = once(() => {
                 stages.hide()
 
                 // Adding an "isConnected" check, in case the callback
@@ -409,19 +408,11 @@ export function transition(el, stages) {
                     stages.cleanup()
                 }
 
-                // Safe to remove transition from el since it is completed
-                delete el.__x_transition_remaining
-                if(el.__x_transition_timer){
-                    clearTimeout(el.__x_transition_timer)
-                }
-            }
+                 // Safe to remove transition from el since it is completed
+                 delete el.__x_transition_remaining
+            })
 
-            el.__x_transition_timer = setTimeout(() => {
-                // We only want to run remaining transitions in the end if they exists
-                if (el.__x_transition_remaining) {
-                    el.__x_transition_remaining()
-                }
-            }, duration);
+            setTimeout(el.__x_transition_remaining, duration);
         })
     });
 }
@@ -429,3 +420,16 @@ export function transition(el, stages) {
 export function isNumeric(subject){
     return ! isNaN(subject)
 }
+
+/**
+ * Ensure a function is called only once.
+ */
+export function once(fn) {
+    let called = false
+    return function () {
+        if (!called) {
+            called = true
+            fn.apply(this, arguments)
+        }
+    }
+}