Ver Fonte

fixed repainting terminating the current transition

Muzaffer Dede há 5 anos atrás
pai
commit
ed1108784b
4 ficheiros alterados com 38 adições e 12 exclusões
  1. 17 6
      dist/alpine.js
  2. 6 0
      examples/index.html
  3. 9 4
      src/directives/show.js
  4. 6 2
      src/utils.js

+ 17 - 6
dist/alpine.js

@@ -197,6 +197,7 @@
     }
   }
   function transitionOut(el, hide, component, forceSkip = false) {
+    // We don't want to transition on the initial page load.
     if (forceSkip) return hide();
     const attrs = getXAttrs(el, component, 'transition');
     const showAttr = getXAttrs(el, component, 'show')[0];
@@ -416,9 +417,13 @@
 
 
           delete el.__x_remaining_transitions;
+
+          if (el.__x_transition_timer) {
+            clearTimeout(el.__x_transition_timer);
+          }
         };
 
-        setTimeout(() => {
+        el.__x_transition_timer = setTimeout(() => {
           // We only want to run remaining transitions in the end if they exists
           if (el.__x_remaining_transitions) {
             el.__x_remaining_transitions();
@@ -647,7 +652,7 @@
 
   function handleShowDirective(component, el, value, modifiers, initialUpdate = false) {
     // Resolve any previous pending transitions before starting a new one
-    if (el.__x_remaining_transitions) {
+    if (el.__x_remaining_transitions && el.__x_current_transition_value !== value) {
       el.__x_remaining_transitions();
     }
 
@@ -694,11 +699,14 @@
           transitionIn(el, () => {
             show();
           }, component);
-        } // Resolve immediately, only hold up parent `x-show`s for hidin.
+        } // Resolve immediately, only hold up parent `x-show`s for hiding.
 
 
         resolve(() => {});
-      }
+      } // Asign current value to el to check later on for preventing transition overlaps
+
+
+      el.__x_current_transition_value = value;
     }; // The working of x-show is a bit complex because we need to
     // wait for any child transitions to finish before hiding
     // some element. Also, this has to be done recursively.
@@ -715,10 +723,13 @@
 
     if (component.showDirectiveLastElement && !component.showDirectiveLastElement.contains(el)) {
       component.executeAndClearRemainingShowDirectiveStack();
-    } // We'll push the handler onto a stack to be handled later.
+    } // If x-show value changed from previous transition we'll push the handler onto a stack to be handled later.
 
 
-    component.showDirectiveStack.push(handle);
+    if (el.__x_current_transition_value !== value) {
+      component.showDirectiveStack.push(handle);
+    }
+
     component.showDirectiveLastElement = el;
   }
 

+ 6 - 0
examples/index.html

@@ -38,6 +38,12 @@
         <script src="/dist/alpine.js" defer></script>
     </head>
     <body>
+        <div x-data="{open: false, foo: ''}">
+            <div x-show.transition.duration.5000="open">test</div>
+            <button @click="open = !open">toggle</button>
+            <div x-text="open"></div>
+            <input x-model="foo">
+          </div>
         <table>
             <thead>
                 <tr>

+ 9 - 4
src/directives/show.js

@@ -2,7 +2,7 @@ import { transitionIn, transitionOut } from '../utils'
 
 export function handleShowDirective(component, el, value, modifiers, initialUpdate = false) {
     // Resolve any previous pending transitions before starting a new one
-    if (el.__x_remaining_transitions) {
+    if (el.__x_remaining_transitions && el.__x_current_transition_value !== value) {
         el.__x_remaining_transitions()
     }
 
@@ -50,9 +50,12 @@ export function handleShowDirective(component, el, value, modifiers, initialUpda
                 }, component)
             }
 
-            // Resolve immediately, only hold up parent `x-show`s for hidin.
+            // Resolve immediately, only hold up parent `x-show`s for hiding.
             resolve(() => {})
         }
+
+        // Asign current value to el to check later on for preventing transition overlaps
+        el.__x_current_transition_value = value
     }
 
     // The working of x-show is a bit complex because we need to
@@ -72,8 +75,10 @@ export function handleShowDirective(component, el, value, modifiers, initialUpda
         component.executeAndClearRemainingShowDirectiveStack()
     }
 
-    // We'll push the handler onto a stack to be handled later.
-    component.showDirectiveStack.push(handle)
+    // If x-show value changed from previous transition we'll push the handler onto a stack to be handled later.
+    if (el.__x_current_transition_value !== value) {
+        component.showDirectiveStack.push(handle)
+    }
 
     component.showDirectiveLastElement = el
 }

+ 6 - 2
src/utils.js

@@ -179,6 +179,7 @@ export function transitionIn(el, show, component, forceSkip = false) {
 }
 
 export function transitionOut(el, hide, component, forceSkip = false) {
+     // We don't want to transition on the initial page load.
     if (forceSkip) return hide()
 
     const attrs = getXAttrs(el, component, 'transition')
@@ -398,7 +399,7 @@ export function transition(el, stages) {
             stages.end()
 
             // Asign current transition to el in case we need to force it
-            el.__x_remaining_transitions = () => {
+            el.__x_remaining_transitions =() => {
 
                 stages.hide()
 
@@ -410,9 +411,12 @@ export function transition(el, stages) {
 
                 // Safe to remove transition from el since it is completed
                 delete el.__x_remaining_transitions
+                if(el.__x_transition_timer){
+                    clearTimeout(el.__x_transition_timer)
+                }
             }
 
-            setTimeout(() => {
+            el.__x_transition_timer = setTimeout(() => {
                 // We only want to run remaining transitions in the end if they exists
                 if (el.__x_remaining_transitions) {
                     el.__x_remaining_transitions()