Author: bargull
Date: 2008-02-12 09:34:13 -0800 (Tue, 12 Feb 2008)
New Revision: 8007

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/LzLibraryCleanup.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzLibrary.js
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibrary.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibraryLoader.lzs
   openlaszlo/trunk/WEB-INF/lps/schema/lfc.lzx
Log:
Change 20080211-bargull-6 by [EMAIL PROTECTED] on 2008-02-11 22:46:58
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Cleanup for LzLibrary

New Features:

Bugs Fixed: LPP-5419, LPP-4227

Technical Reviewer: hminsky
QA Reviewer: (pending)
Doc Reviewer: dda

Documentation:

Release Notes:

Details:
Only a couple of minor fixes and improvements:
- added attributes/events to the LzLibrary classes (SWF,DHTML)
- moved code from LzLibraryCleanup to LzLibrary (LzLibrary#loadfinished(..)) 
(OOP-thingy)
- added "loaded"/"loading" states for DHTML (were already supported in SWF)
- fixed: LzLibrary#destroy(..) did not destroy the library-sprite
- removed old code in LzLibrary#unload() (SWF) ("delete this.__LZmovieClipRef" 
is no longer necessary, was for OL3.x)
- LzLibraryLoader#snippetLoaded(..) did not properly update "loaded"/"loading" 
states, did not fire "ontimeout"-event, etc.
- added docs for attributes/methods


Tests:



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/LzLibraryCleanup.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/LzLibraryCleanup.lzs        
2008-02-12 17:09:26 UTC (rev 8006)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/LzLibraryCleanup.lzs        
2008-02-12 17:34:13 UTC (rev 8007)
@@ -18,13 +18,10 @@
   */
     static var tagname = '__libraryloadercomplete';
 
-
     function LzLibraryCleanup ( owner , args ) {
-        //this.callInherited( "constructor", arguments.callee ,owner ,args );
         super(owner, args);
         var lib = LzLibrary.findLibrary(args.libname);
-        lib.loading = false;
-        if (lib.onload.ready) lib.onload.sendEvent(true);
+        lib.loadfinished();
     }
 
 }; // End of LzLibraryCleanup

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzLibrary.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzLibrary.js  2008-02-12 
17:09:26 UTC (rev 8006)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzLibrary.js  2008-02-12 
17:34:13 UTC (rev 8007)
@@ -1,7 +1,7 @@
 /**
   * LzLibrary.as
   *
-  * @copyright Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.
+  * @copyright Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.
   *            Use is subject to license terms.
   *
   * @topic LZX
@@ -19,7 +19,44 @@
   */
 static var tagname = 'import';
 
+/** @access private */
+var loaded = false;
+/** @access private */
+var loading = false;
+/** @access private */
+var sprite = null;
+
 /**
+ * A reference to a target file whose content is treated as a 
+ * loadable module.
+ * 
+ * @keywords final
+ * @type string
+ * @access public 
+ */
+var href;
+
+/** 
+ * When set to 'defer', the library will not be loaded until its 
+ * load-method has been called. Otherwise, the library loads 
+ * automatically. 
+ * 
+ * @keywords final
+ * @type string 
+ * @lzxdefault "late"
+ * @access public 
+ */
+var stage = "late";//"late|defer"
+
+/**
+ * Sent when this library has finished loading. 
+ * 
+ * @lzxtype event
+ * @access public
+ */
+var onload = LzDeclaredEvent;
+
+/**
   * @access private
   */
 function construct (parent, args) {
@@ -39,8 +76,19 @@
     }
 }
 
+/**
+  * @access private
+  */
+function destroy () {
+    if (this.sprite) {
+        this.sprite.destroy();
+        this.sprite = null;
+    }
+    super.destroy.apply(this, arguments);
+}
 
-static var libraries = [];
+/** @access private */
+static var libraries = {};
 
 /**
   * @access private
@@ -49,41 +97,60 @@
     return LzLibrary.libraries[libname];
 }
 
-var loaded = false;
-var loading = false;
-var onload = LzDeclaredEvent;
-
+/**
+  * @access private
+  */
 function toString (){
     return "Library " + this.href + " named " + this.name;
 }
 
 /**
-  * @access private
+  * Loads this library dynamically at runtime. Must only be called 
+  * when stage was set to 'defer'.
+  * 
+  * @access public
   */
 function load (){
+    if (this.loading || this.loaded) {
+        return;
+    }
+    this.loading = true;
     Lz.__dhtmlLoadLibrary(this.href);
 }
 
+/** 
+ * Called by LzLibraryCleanup when this library has finished loading.
+ * 
+ * @access private 
+ */
+function loadfinished (){
+  this.loading = false;
+  if (this.onload.ready) this.onload.sendEvent(true);
+}
+
 /**
   * Callback for runtime loaded libraries
   * @access private
   */
 static function __LZsnippetLoaded (url){
     // find the lib with this url
-    var libname = null;
+    var lib = null;
     var libs = LzLibrary.libraries;
     for (var l in libs ) {
         if (libs[l].href == url) {
-            libname = libs[l].name;
+            lib = libs[l];
             break;
         }
     }
-    if (libname == null) {
+    
+    if (lib == null) {
         Debug.error("could not find library with href", url);
+    } else {
+        lib.loaded = true;
+        LzInstantiateView({attrs: {libname: lib.name}, name: 
"__libraryloadercomplete"}, 1);
+        // Run the queue to instantiate all pending LzInstantiateView calls.
+        canvas.initDone();
     }
-    LzInstantiateView({attrs: {libname: libname}, name: 
"__libraryloadercomplete"}, 1);
-    // Run the queue to instantiate all pending LzInstantiateView calls.
-    canvas.initDone();
 }
 
 }; // End of LzLibrary

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibrary.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibrary.lzs   2008-02-12 
17:09:26 UTC (rev 8006)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibrary.lzs   2008-02-12 
17:34:13 UTC (rev 8007)
@@ -1,7 +1,7 @@
 /**
   * LzLibrary.as
   *
-  * @copyright Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.
+  * @copyright Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.
   *            Use is subject to license terms.
   *
   * @topic LZX
@@ -19,7 +19,70 @@
   */
 static var tagname = 'import';
 
+/** @access private */
+var loaded = false;
+/** @access private */
+var loading = false;
+/** @access private */
+var sprite = null;
+/** @access private */
+var loader;
+
 /**
+ * A reference to a target file whose content is treated as a 
+ * loadable module.
+ * 
+ * @keywords final
+ * @type string
+ * @access public 
+ */
+var href;
+
+/** 
+ * When set to 'defer', the library will not be loaded until its 
+ * load-method has been called. Otherwise, the library loads 
+ * automatically. 
+ * 
+ * @keywords final
+ * @type string 
+ * @lzxdefault "late"
+ * @access public 
+ */
+var stage = "late";//"late|defer"
+
+/** 
+ * @keywords final
+ * @type inheritableBoolean
+ * @lzxdefault "inherit"
+ * @access public 
+ */
+var proxied = null;
+
+/**
+ * Sent when this library has finished loading. 
+ * 
+ * @lzxtype event
+ * @access public
+ */
+var onload = LzDeclaredEvent;
+
+/**
+ * Sent when the request to load this library times out. 
+ * 
+ * @lzxtype event
+ * @access public
+ */
+var ontimeout = LzDeclaredEvent;
+
+/**
+ * Sent when there is an error loading this library. 
+ * 
+ * @lzxtype event
+ * @access public
+ */
+var onerror = LzDeclaredEvent;
+
+/**
   * @access private
   */
 function construct (parent, args) {
@@ -39,9 +102,9 @@
     }
 }
 
+/** @access private */
+static var libraries = {};
 
-static var libraries = [];
-
 /**
   * @access private
   */
@@ -49,15 +112,18 @@
     return LzLibrary.libraries[libname];
 }
 
-var loaded = false;
-var loading = false;
-
+/**
+  * @access private
+  */
 function toString (){
     return "Library " + this.href + " named " + this.name;
 }
 
 /**
-  * @access private
+  * Loads this library dynamically at runtime. Must only be called 
+  * when stage was set to 'defer'.
+  * 
+  * @access public
   */
 function load (){
   if (this.loading || this.loaded) {
@@ -65,12 +131,13 @@
   }
   this.loading = true;
   this.sprite.makeContainerResource();
-  var loader = this.loader = new LzLibraryLoader(this.sprite);
+  var loader = (this.loader = new LzLibraryLoader(this.sprite));
 
-  var proxied = canvas.proxied;
   // check if this library has a "proxied" attribute which overrides canvas 
switch
-  if (typeof(this.proxied) != "undefined" && this.proxied != null) {
-      proxied = (this.proxied == true);
+  if (this.proxied != null) {
+      var proxied = (this.proxied == true);
+  } else {
+      var proxied = canvas.proxied;
   }
 
   loader.proxied = proxied;
@@ -78,6 +145,16 @@
   loader.request( this.href );
 }
 
+/** 
+ * Called by LzLibraryCleanup when this library has finished loading.
+ * 
+ * @access private 
+ */
+function loadfinished (){
+  this.loading = false;
+  if (this.onload.ready) this.onload.sendEvent(true);
+}
+
 /**
   * To 'unload' a snippet, three things have to be done:
   * 1. Destroy all the instances that were created by the snippet.
@@ -113,11 +190,9 @@
   }
   this.loader.destroy();
   delete this.loader;
+  
   this.loading = false;
   this.loaded = false;
-  // TODO: [2005-08-31 ptw] Horrible modularity here, but
-  // loader.unload leaves this with a husk
-  delete this.__LZmovieClipRef
 }
 
 /**
@@ -125,6 +200,10 @@
   */
 function destroy () {
     this.unload();
+    if (this.sprite) {
+        this.sprite.destroy();
+        this.sprite = null;
+    }
     super.destroy.apply(this, arguments);
 }
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibraryLoader.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibraryLoader.lzs     
2008-02-12 17:09:26 UTC (rev 8006)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzLibraryLoader.lzs     
2008-02-12 17:34:13 UTC (rev 8007)
@@ -38,26 +38,22 @@
 /**
   * @access private
   */
-
-/**
-  * @access private
-  */
 function getLoadMC (){
     return this.mc.lmc;
 }
 
-
-
 /**
   * @access private
   */
 // This is the callback when a library module has finished loading
 function snippetLoaded ( loadmc, err ){
-    Debug.write("snippetLoaded", 'loadmc=', loadmc, this);
+    // our 'owner' is a sprite, and the sprite's owner is the LzLibrary
+    var lib = this.owner.owner;
+    
     LzLoadQueue.loadFinished( loadmc );
     if ( ! loadmc.valid ) {
-        this.owner.loaded = false;
-        this.owner.loading = false;
+        lib.loaded = false;
+        lib.loading = false;
         return;
     }
 
@@ -70,23 +66,20 @@
     // this snippetLoaded method with an error arg.
 
     if ( err != null ){
-      //Debug.write( err );
-        this.owner.loaded = true;
-        this.owner.loading = false;
-        if (this.owner.onerror.ready) this.owner.onerror.sendEvent( err );
+        lib.loaded = true;
+        lib.loading = false;
+        if (lib.onerror.ready) lib.onerror.sendEvent( err );
         return;
     }
 
     if ( loadmc.timedout ){
         this.doTimeOut();
+        if (lib.ontimeout.ready) lib.ontimeout.sendEvent();
     } else {
-        // this.owner.onload.sendEvent( err );
-        this.owner.loaded = true;
+        lib.loaded = true;
     }
 
-    // our 'owner' is a sprite, and the sprite's owner is the LzLibrary
-    var libname = this.owner.owner.name
-    LzInstantiateView({attrs: {libname: libname}, name: 
"__libraryloadercomplete"}, 1);
+    LzInstantiateView({attrs: {libname: lib.name}, name: 
"__libraryloadercomplete"}, 1);
     
     // Run the queue to instantiate all pending LzInstantiateView calls.
     canvas.initDone();

Modified: openlaszlo/trunk/WEB-INF/lps/schema/lfc.lzx
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/schema/lfc.lzx 2008-02-12 17:09:26 UTC (rev 
8006)
+++ openlaszlo/trunk/WEB-INF/lps/schema/lfc.lzx 2008-02-12 17:34:13 UTC (rev 
8007)
@@ -8,7 +8,7 @@
  Note: We are going to have to generate the lzx.dtd, lzx.rng, lzx.xsd, and 
lzxdoc.rng
  from this file. 
  * P_LZ_COPYRIGHT_BEGIN ******************************************************
- * Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.            *
+ * Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.            *
  * Use is subject to license terms.                                          *
  * P_LZ_COPYRIGHT_END ********************************************************
 -->
@@ -500,7 +500,6 @@
 
 
 <interface name="import" extends="node">
-  <!-- A reference to a target file whose content is treated as a loadable 
module -->
   <attribute name="href" type="string" />
   <attribute name="stage" type="string" value="late" enum="late|defer" />
   <event name="onload"/>


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to