Personal tools

Legals Porting

From OpenLaszlo

(Difference between revisions)
Revision as of 14:30, 12 January 2007
Pbr (Talk | contribs)
(Porting lzs code to the new Class system)
← Previous diff
Revision as of 14:31, 12 January 2007
Pbr (Talk | contribs)
(Static Functions)
Next diff →
Line 166: Line 166:
 +You can ignore this. Tucker fixed it a while back.
- +<strike>
Must move $debug blocks outside the class definition Must move $debug blocks outside the class definition
-<pre>+ 
if ($debug) { if ($debug) {
//--- //---
} }
-</pre> 
and continue to use the old class notation and continue to use the old class notation
 +</strike>

Revision as of 14:31, 12 January 2007

Porting to new class system


Contents

Defining a Class


Old: ---

LzNode = Class( "LzNode" , null , mvn() );
var mvn = function (){
   var f = function ( parent , attrs , children , instcall ){
       ...
   };
   return f;
}

New:


initialize() is the class constructor

class LzNode {
function initialize ( parent , attrs , children , instcall ){
   ...
}
...
}


A static initialize() function runs once for each class

// From LzNode.lzs
static function initialize (prototype) {
 // Ensure you have your own private dictionaries, not one
 // inherited from your superclass
 for (var hash in {setters: true, getters: true, defaultattrs: true,
__LZdelayedSetters: true, earlySetters: true} ) {
   if (! prototype.hasOwnProperty(hash)) {
     prototype[hash] = new LzInheritedHash(prototype[hash]);
   }
 }
}


Deriving from a base class:

class LzView extends LzNode {
}


Deriving from a trait:

The need for 'Instance' is only needed is there is no base class.

class LzDataText extends LzDataNode, Instance {
}



Defining variables

LzNode.prototype.defaultattrs = { $hasdefaultattrs : true };
LzNode.prototype.datapath = null;
LzNode.prototype.setters ={
   name : "setName" ,
   id : "setID" ,
   $events : "__LZsetEvents" ,
   $refs : "__LZstoreRefs" ,
   $delegates : "__LZstoreDelegates" ,
   placement : -1 ,
   datapath : "setDatapath",
   $setters : -1,
   $classrootdepth : "__LZsetClassRoot",
   $datapath : "__LZmakeDatapath"
}


var defaultattrs = { $hasdefaultattrs : true };
var datapath = null;
var setters ={
   name : "setName" ,
   id : "setID" ,
   $events : "__LZsetEvents" ,
   $refs : "__LZstoreRefs" ,
   $delegates : "__LZstoreDelegates" ,
   placement : -1 ,
   datapath : "setDatapath",
   $setters : -1,
   $classrootdepth : "__LZsetClassRoot",
   $datapath : "__LZmakeDatapath"
};


Overriding variable values

OLD:

LzState:
LzState.prototype.$isstate = true;

New:

LzNode.lzs:
   var $isstate = false;
LzState.lzs:
   prototype.$isstate = true;



Static Functions

OLD:

LzView.__LZproxypolicies = [];

LzView.__LZcheckProxyPolicy= function ( url ){
   var pol = _root.LzView.__LZproxypolicies;
   for ( var i = pol.length-1; i >=0; i-- ){
       var resp = pol[ i ] ( url );
       if ( resp != null ) return resp;
   }
   return _root.canvas.proxied;
}


NEW:

static var __LZproxypolicies = [];
//-----------------------------------------------------------------------------
// @keywords private
//-----------------------------------------------------------------------------
static function __LZcheckProxyPolicy ( url ){
   var pol = LzView.__LZproxypolicies;
   for ( var i = pol.length-1; i >=0; i-- ){
       var resp = pol[ i ] ( url );
       if ( resp != null ) return resp;
   }
   return canvas.proxied;
}


You can ignore this. Tucker fixed it a while back.

Must move $debug blocks outside the class definition

if ($debug) { //--- }

and continue to use the old class notation