[Laszlo-dev] Any gotchas I should know about for converting old Class code to new class syntax?
John Sundman
jsundman at laszlosystems.com
Fri Jan 12 06:04:25 PST 2007
For b2 I will be preparing a Porting Guide. I'll make sure this is
covered there.
In the meantime, Phil, would you put this in the Wiki?
jrs
On Jan 12, 2007, at 2:33 AM, P T Withington wrote:
> Any chance of getting this into the Wiki, whereever we have Legal's
> porting notes?
>
> On 2007-01-09, at 17:01 PST, Philip Romanik wrote:
>
>> Hi Tucker,
>>
>> I was about to say I don't have anything written down, but then I
>> found some notes. I'm attaching the list. I removed the last item
>> in my notes because it is no longer relevant (it was about moving
>> $debug blocks after the class which is no longer an issue).
>> Unfortunately, the notes aren't complete but Henry can look at the
>> existing code for guidance.
>>
>> Phil
>>
>> =====================
>>
>> 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;
>> }
>>
>>
>>
>> =====================
>>
>>
>>> Not if all it does is define attributes and methods. If it is doing
>>> anything other than that, feel free to ask. (I'm hoping PhilR has a
>>> checklist that he can send you...)
>>>
>>> On 2007-01-09, at 09:52 PST, Henry Minsky wrote:
>>>
>>> > I'm converting the rpc library code which uses the old "Class"
>>> > mechanism to use the new"class" syntax, just wondering if there
>>> are
>>> > any
>>> > gotchas I should know about, mostly asking PhilR and Tucker if
>>> > there there's anything non-obvious
>>> > I should watch out for.
>>> >
>>
>
More information about the Laszlo-dev
mailing list