flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/3] git commit: [flex-asjs] [refs/heads/develop] - try optimizing what gets added/removed to reduce number of layout passes
Date Tue, 19 May 2015 18:57:07 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 080630b19 -> 56f594cd2


try optimizing what gets added/removed to reduce number of layout passes


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/56f594cd
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/56f594cd
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/56f594cd

Branch: refs/heads/develop
Commit: 56f594cd2fbe0b56d97bff8674221d26ca2230f1
Parents: cb5c064
Author: Alex Harui <aharui@apache.org>
Authored: Tue May 19 11:56:19 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue May 19 11:57:00 2015 -0700

----------------------------------------------------------------------
 .../flex/core/StatesWithTransitionsImpl.as      | 103 ++++++++++++++-----
 1 file changed, 75 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/56f594cd/frameworks/projects/Effects/asjs/src/org/apache/flex/core/StatesWithTransitionsImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Effects/asjs/src/org/apache/flex/core/StatesWithTransitionsImpl.as
b/frameworks/projects/Effects/asjs/src/org/apache/flex/core/StatesWithTransitionsImpl.as
index 3e72d43..9549bc8 100644
--- a/frameworks/projects/Effects/asjs/src/org/apache/flex/core/StatesWithTransitionsImpl.as
+++ b/frameworks/projects/Effects/asjs/src/org/apache/flex/core/StatesWithTransitionsImpl.as
@@ -18,12 +18,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.core
 {
-    
-    import org.apache.flex.states.AddItems;
-    import org.apache.flex.states.SetEventHandler;
-    import org.apache.flex.states.SetProperty;
-    import org.apache.flex.states.State;
-    
+        
     import org.apache.flex.core.IParent;
     import org.apache.flex.core.IStatesObject;
     import org.apache.flex.effects.Effect;
@@ -31,6 +26,10 @@ package org.apache.flex.core
     import org.apache.flex.events.EventDispatcher;
     import org.apache.flex.events.IEventDispatcher;
     import org.apache.flex.events.ValueChangeEvent;
+    import org.apache.flex.states.AddItems;
+    import org.apache.flex.states.SetEventHandler;
+    import org.apache.flex.states.SetProperty;
+    import org.apache.flex.states.State;
     import org.apache.flex.states.Transition;
     import org.apache.flex.utils.MXMLDataInterpreter;
 	
@@ -122,11 +121,13 @@ package org.apache.flex.core
                 }
             }
             var arr:Array = doc.states;
+            var oldState:State;
+            var newState:State;
             for each (var s:State in arr)
             {
                 if (s.name == event.oldValue)
                 {
-                    revert(s);
+                    oldState = s;
                     break;
                 }
             }
@@ -134,10 +135,14 @@ package org.apache.flex.core
             {
                 if (s.name == event.newValue)
                 {
-                    apply(s);
+                    newState = s;
                     break;
                 }
             }
+            if (oldState)
+                revert(oldState, newState);
+            if (newState)
+                apply(oldState, newState);
             if (transitionEffects && transitionEffects.length > 0)
             {
                 for each (e in transitionEffects)
@@ -185,8 +190,39 @@ package org.apache.flex.core
                 doc.dispatchEvent(new Event("stateChangeComplete"));
             }
         }
+        
+        private function isItemInState(child:Object, s:State):Boolean
+        {
+            if (s == null) return false;
             
-        private function revert(s:State):void
+            var arr:Array = s.overrides;
+            for each (var o:Object in arr)
+            {
+                if (o is AddItems)
+                {
+                    var ai:AddItems = AddItems(o);
+                    if (ai.items == null)
+                    {
+                        ai.items = ai.itemsDescriptor.items as Array;
+                        if (ai.items == null)
+                        {
+                            ai.items = 
+                                MXMLDataInterpreter.generateMXMLArray(ai.document,
+                                    null, ai.itemsDescriptor.descriptor);
+                            ai.itemsDescriptor.items = ai.items;
+                        }
+                    }
+                    for each (var item:IChild in ai.items)
+                    {
+                        if (item == child)
+                            return true;
+                    }
+                }
+            }
+            return false;
+        }
+        
+        private function revert(s:State, newState:State):void
         {
             var arr:Array = s.overrides;
             for each (var o:Object in arr)
@@ -194,12 +230,17 @@ package org.apache.flex.core
                 if (o is AddItems)
                 {
                     var ai:AddItems = AddItems(o);
+                    var childrenAdded:Boolean = false;
                     for each (var item:IChild in ai.items)
                     {
-                        var parent:IParent = item.parent as IParent;
-                        parent.removeElement(item);
+                        if (!isItemInState(item, newState))
+                        {
+                            var parent:IParent = item.parent as IParent;
+                            parent.removeElement(item);
+                            childrenAdded = true;
+                        }
                     }
-                    if (parent is IContainer)
+                    if (childrenAdded && parent is IContainer)
                         IContainer(parent).childrenAdded();
                 }
                 else if (o is SetProperty)
@@ -225,7 +266,7 @@ package org.apache.flex.core
             }
         }
         
-        private function apply(s:State):void
+        private function apply(oldState:State, s:State):void
         {
             var arr:Array = s.overrides;
             for each (var o:Object in arr)
@@ -244,27 +285,33 @@ package org.apache.flex.core
                             ai.itemsDescriptor.items = ai.items;
                         }
                     }
+                    var childrenAdded:Boolean = false;
                     for each (var item:Object in ai.items)
                     {
-                        var parent:IParent = ai.document as IParent;
-                        if (ai.destination)
-                            parent = parent[ai.destination] as IParent;
-                        if (ai.relativeTo != null)
+                        if (!isItemInState(item, oldState))
                         {
-                            var child:Object = ai.document[ai.relativeTo];
+                            var parent:IParent = ai.document as IParent;
                             if (ai.destination)
-                                parent = IChild(child).parent as IParent;
-                            var index:int = parent.getElementIndex(child);
-                            if (ai.position == "after")
-                                index++;
-                            parent.addElementAt(item, index);
-                        }
-                        else
-                        {
-                            parent.addElement(item);
+                                parent = parent[ai.destination] as IParent;
+                            if (ai.relativeTo != null)
+                            {
+                                var child:Object = ai.document[ai.relativeTo];
+                                if (ai.destination)
+                                    parent = IChild(child).parent as IParent;
+                                var index:int = parent.getElementIndex(child);
+                                if (ai.position == "after")
+                                    index++;
+                                parent.addElementAt(item, index);
+                                childrenAdded = true;
+                            }
+                            else
+                            {
+                                parent.addElement(item);
+                                childrenAdded = true;
+                            }
                         }
                     }
-                    if (parent is IContainer)
+                    if (childrenAdded && parent is IContainer)
                         IContainer(parent).childrenAdded();
                 }
                 else if (o is SetProperty)


Mime
View raw message