royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [royale-asjs] 01/03: module loader for emulation components
Date Sun, 12 Aug 2018 00:36:57 GMT
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch feature/MXRoyale
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit b4068222b4e8b934df80e5b632122436286fa477
Author: Alex Harui <aharui@apache.org>
AuthorDate: Fri Aug 10 15:46:25 2018 -0700

    module loader for emulation components
---
 .../projects/Basic/src/main/royale/BasicClasses.as |   3 +
 .../org/apache/royale/html/UIModuleLoader.as       | 128 ++-------------------
 .../UIModuleLoader.as => utils/UIModuleUtils.as}   |  43 ++++---
 .../src/main/royale/mx/modules/ModuleLoader.as     |  33 +++---
 4 files changed, 53 insertions(+), 154 deletions(-)

diff --git a/frameworks/projects/Basic/src/main/royale/BasicClasses.as b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
index ef6ef6e..f0c3701 100644
--- a/frameworks/projects/Basic/src/main/royale/BasicClasses.as
+++ b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
@@ -298,6 +298,9 @@ internal class BasicClasses
 	import org.apache.royale.html.beads.models.TreeGridModel; TreeGridModel;
 	import org.apache.royale.html.beads.layouts.TreeGridLayout; TreeGridLayout;
 	import org.apache.royale.html.beads.TreeGridView; TreeGridView;
+    
+    import org.apache.royale.utils.UIModuleUtils; UIModuleUtils;
+
 }
 
 }
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/UIModuleLoader.as
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/UIModuleLoader.as
index 3667d38..63b7a34 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/UIModuleLoader.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/UIModuleLoader.as
@@ -21,6 +21,7 @@ package org.apache.royale.html
 	import org.apache.royale.core.IUIBase;
 	import org.apache.royale.core.UIBase;
 	import org.apache.royale.utils.PointUtils;
+    import org.apache.royale.utils.UIModuleUtils;
 	import org.apache.royale.geom.Point;
 	import org.apache.royale.events.Event;
 	
@@ -64,8 +65,6 @@ package org.apache.royale.html
 			super();
 		}
 		
-        private var _modulePath:String;
-        
         /**
          *  Path or URL of module.  This is combined
          *  with the module name and a platform suffix
@@ -79,7 +78,7 @@ package org.apache.royale.html
          */
         public function get modulePath():String
         {
-            return _modulePath;
+            return utils.modulePath;
         }
         
         /**
@@ -87,75 +86,28 @@ package org.apache.royale.html
          */
         public function set modulePath(value:String):void
         {
-            _modulePath = value;
+            utils.modulePath = value;
         }
         
-        private var _moduleName:String;
-        
         public function get moduleName():String
         {
-            return _moduleName;
+            return utils.moduleName;
         }
         
         public function set moduleName(value:String):void
         {
-            _moduleName = value;
+            utils.moduleName = value;
         }
-        
-		COMPILE::SWF
-		private var swfLoader:Loader;
-		
-		COMPILE::JS
-		private var jsLoader:WrappedHTMLElement;
-
-        COMPILE::JS
-        private var jsDepsLoader:WrappedHTMLElement;
-        
+                
         override public function addedToParent():void
         {
             super.addedToParent();
-            if (_modulePath)
+            if (utils.moduleName)
                 loadModule();
         }
-        
-		/**
-		 * @private
-		 * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
-		 */
-		private function createLoader():void
-		{
-			COMPILE::SWF {				
-				if (swfLoader != null) {
-                    swfLoader.contentLoaderInfo.removeEventListener("complete", completeHandler);
-				}
-				
-				swfLoader = new Loader();
-                swfLoader.contentLoaderInfo.addEventListener("complete", completeHandler);
-			}
-				
-			COMPILE::JS {
-				var origin:Point = new Point(0,0);
-				var xlated:Point = PointUtils.localToGlobal(origin, parent);
-				
-                if (goog.DEBUG)
-                {
-                    if (jsDepsLoader == null) {
-                        jsDepsLoader = document.createElement('script') as WrappedHTMLElement;
-                        jsDepsLoader.onload = loadDepsHandler;
-                        document.body.appendChild(jsDepsLoader);
-                    }                    
-                }
-                else
-                {
-    				if (jsLoader == null) {
-    					jsLoader = document.createElement('script') as WrappedHTMLElement;
-                        jsLoader.onload = loadHandler;
-    					document.body.appendChild(jsLoader);
-    				}
-                }
-			}
-		}
 		
+        private var utils:UIModuleUtils = new UIModuleUtils();
+        
 		/**
          *  Load the module.  Will be called automatically if modulePath
          *  is set as the UIModuleLoader is added to the display list.
@@ -167,67 +119,7 @@ package org.apache.royale.html
 		 */
 		public function loadModule():void
 		{
-            if (moduleInstance)
-                removeElement(moduleInstance);
-            
-			createLoader();
-			
-			COMPILE::SWF {
-				var url:URLRequest = new URLRequest(modulePath ? modulePath + "/" + moduleName + ".swf"
:
-                                                    moduleName + ".swf");
-				var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain,
null);
-				swfLoader.load(url, loaderContext);
-				if (swfLoader.parent == null) {
-					addChild(swfLoader);
-				}
-			}
-				
-			COMPILE::JS {
-                if (!goog.DEBUG)
-    	   			jsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName + ".js"
:
-                        moduleName + ".js");
-                else
-                {
-                    // js-debug module loading requires that the __deps.js file has been
tweaked
-                    // so that the path to the module class is correct and that any
-                    // framework js files have been copied into the same tree structure as
-                    // the main apps framework js files
-                    window["goog"]["ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING"] = true;
-                    jsDepsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName
+ "__deps.js" :
-                        moduleName + "__deps.js");
-                }
-			}
-		}
-        
-        private var moduleInstance:IUIBase;
-        
-        COMPILE::SWF
-        protected function completeHandler(event:flash.events.Event):void
-        {
-            var c:Class = ApplicationDomain.currentDomain.getDefinition(moduleName) as Class;
-            moduleInstance = new c() as IUIBase;
-            addElement(moduleInstance);
-        }
-        
-        COMPILE::JS
-        protected function loadDepsHandler():void
-        {
-            // wait for other scripts to load
-            if (window[moduleName] == null)
-            {
-                setTimeout(loadDepsHandler, 250);
-            }
-            else
-                loadHandler();
-                
-        }
-        
-        COMPILE::JS
-        protected function loadHandler():void
-        {
-            var c:Class = window[moduleName];
-            moduleInstance = new c() as IUIBase;
-            addElement(moduleInstance);
+            utils.loadModule(this);
         }
 	}
 }
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/UIModuleLoader.as
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/utils/UIModuleUtils.as
similarity index 90%
copy from frameworks/projects/Basic/src/main/royale/org/apache/royale/html/UIModuleLoader.as
copy to frameworks/projects/Basic/src/main/royale/org/apache/royale/utils/UIModuleUtils.as
index 3667d38..fe557cf 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/UIModuleLoader.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/utils/UIModuleUtils.as
@@ -16,13 +16,13 @@
 //  limitations under the License.
 //
 ////////////////////////////////////////////////////////////////////////////////
-package org.apache.royale.html
+package org.apache.royale.utils
 {
+	import org.apache.royale.core.IParentIUIBase;
 	import org.apache.royale.core.IUIBase;
-	import org.apache.royale.core.UIBase;
-	import org.apache.royale.utils.PointUtils;
-	import org.apache.royale.geom.Point;
 	import org.apache.royale.events.Event;
+	import org.apache.royale.geom.Point;
+	import org.apache.royale.utils.PointUtils;
 	
 	COMPILE::SWF
 	{
@@ -41,7 +41,7 @@ package org.apache.royale.html
     }
     
     /**
-     *  The UIModuleLoader class can load a UIModule. 
+     *  The UIModuleUtils class can load a UIModule. 
 	 * 
      *  @toplevel
      *  @langversion 3.0
@@ -49,7 +49,7 @@ package org.apache.royale.html
      *  @playerversion AIR 2.6
      *  @productversion Royale 0.0
      */    
-	public class UIModuleLoader extends UIBase
+	public class UIModuleUtils
 	{
         /**
          *  Constructor.
@@ -59,7 +59,7 @@ package org.apache.royale.html
          *  @playerversion AIR 2.6
          *  @productversion Royale 0.0
          */
-		public function UIModuleLoader()
+		public function UIModuleUtils()
 		{
 			super();
 		}
@@ -103,21 +103,14 @@ package org.apache.royale.html
         }
         
 		COMPILE::SWF
-		private var swfLoader:Loader;
+		public var swfLoader:Loader;
 		
 		COMPILE::JS
-		private var jsLoader:WrappedHTMLElement;
+		public var jsLoader:WrappedHTMLElement;
 
         COMPILE::JS
         private var jsDepsLoader:WrappedHTMLElement;
-        
-        override public function addedToParent():void
-        {
-            super.addedToParent();
-            if (_modulePath)
-                loadModule();
-        }
-        
+                
 		/**
 		 * @private
 		 * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
@@ -135,7 +128,7 @@ package org.apache.royale.html
 				
 			COMPILE::JS {
 				var origin:Point = new Point(0,0);
-				var xlated:Point = PointUtils.localToGlobal(origin, parent);
+				var xlated:Point = PointUtils.localToGlobal(origin, host.parent);
 				
                 if (goog.DEBUG)
                 {
@@ -155,6 +148,8 @@ package org.apache.royale.html
                 }
 			}
 		}
+        
+        private var host:IParentIUIBase;
 		
 		/**
          *  Load the module.  Will be called automatically if modulePath
@@ -165,10 +160,12 @@ package org.apache.royale.html
          *  @playerversion AIR 2.6
          *  @productversion Royale 0.0
 		 */
-		public function loadModule():void
+		public function loadModule(host:IParentIUIBase):void
 		{
+            this.host = host;
+            
             if (moduleInstance)
-                removeElement(moduleInstance);
+                host.removeElement(moduleInstance);
             
 			createLoader();
 			
@@ -178,7 +175,7 @@ package org.apache.royale.html
 				var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain,
null);
 				swfLoader.load(url, loaderContext);
 				if (swfLoader.parent == null) {
-					addChild(swfLoader);
+					(host as DisplayObjectContainer).addChild(swfLoader);
 				}
 			}
 				
@@ -206,7 +203,7 @@ package org.apache.royale.html
         {
             var c:Class = ApplicationDomain.currentDomain.getDefinition(moduleName) as Class;
             moduleInstance = new c() as IUIBase;
-            addElement(moduleInstance);
+            host.addElement(moduleInstance);
         }
         
         COMPILE::JS
@@ -227,7 +224,7 @@ package org.apache.royale.html
         {
             var c:Class = window[moduleName];
             moduleInstance = new c() as IUIBase;
-            addElement(moduleInstance);
+            host.addElement(moduleInstance);
         }
 	}
 }
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/modules/ModuleLoader.as b/frameworks/projects/MXRoyale/src/main/royale/mx/modules/ModuleLoader.as
index 450a469..601d6b1 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/modules/ModuleLoader.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/modules/ModuleLoader.as
@@ -33,6 +33,8 @@ import mx.system.ApplicationDomain;
 //import flash.utils.ByteArray;
 //import mx.core.IDeferredInstantiationUIComponent;
 
+import org.apache.royale.utils.UIModuleUtils;
+
 //--------------------------------------
 //  Events
 //--------------------------------------
@@ -207,6 +209,8 @@ public class ModuleLoader extends VBox
         super();
     }
 
+    private var utils:UIModuleUtils = new UIModuleUtils();
+    
     //--------------------------------------------------------------------------
     //
     //  Variables
@@ -221,7 +225,7 @@ public class ModuleLoader extends VBox
     /**
      *  @private
      */
-    //private var loadRequested:Boolean = false;
+    private var loadRequested:Boolean = true;
 
     //--------------------------------------------------------------------------
     //
@@ -283,12 +287,6 @@ public class ModuleLoader extends VBox
     //----------------------------------
 
     /**
-     *  @private
-     *  Storage for the url property.
-     */
-    private var _url:String = null;
-
-    /**
      *  The location of the module, expressed as a URL.
      *  
      *  @langversion 3.0
@@ -298,7 +296,7 @@ public class ModuleLoader extends VBox
      */
     public function get url():String
     {
-        return _url;
+        return utils.modulePath + "/" + utils.moduleName + ".swf";
     }
 
     /**
@@ -306,8 +304,8 @@ public class ModuleLoader extends VBox
      */
      public function set url(value:String):void
     {
-        if (value == _url)
-            return;
+        //if (value == _url)
+        //    return;
 		/*
         var wasLoaded:Boolean = false;
         
@@ -331,12 +329,21 @@ public class ModuleLoader extends VBox
             }
         }
           */
-        _url = value;
+        var c:int = value.lastIndexOf("/");
+        if (c == -1)
+        {
+            utils.modulePath = "";
+            utils.moduleName = value.replace(".swf", "");
+        }
+        else
+        {
+            utils.modulePath = value.substring(0, c);
+            utils.moduleName = value.substring(c + 1).replace(".swf", "");;
+        }
 
         dispatchEvent(new FlexEvent(FlexEvent.URL_CHANGED));
 
-        //if (_url != null && _url != "" && loadRequested)
-        //   loadModule();
+        utils.loadModule(this);
     }
  
 }


Mime
View raw message