Re: setters in swf9
Henry Minsky <henry.minsky <at> gmail.com>
2008-02-01 17:33:22 GMT
We don't have anything that calls the static class initialize method
at all , actually, because we're
not using Tucker's class system anymore. So if we come across any
static initialize method, we need to do whatever it is doing some
other way.
In this case it looks like it's just adding entries to the setters list.
The way I've been doing setters is to declare at the top level of the
class a static class var 'setters' which gets initialized with a new
copy of the superclass setters list (via new
LzInheritedHash(SUPERCLASS.setters)).
Then I just have statements that add stuff to this var
setters.blah = "setBlah"
So in this case, we need to initialize the setters var from the parent
class. So what are the setters
in the superclass? LzDataText extends LzMiniNode_DataNode , so I guess
we should declare, but I
don't see any setters in that class or in LzMiniNode, so we can just
declare a setters
var in LzDataText I think
static var setters = new LzInheritedHash();
setters.ownerDocument = "setOwnerDocument";
Or more compactly
static var setters = new LzInheritedHash({ownerDocument: "setOwnerDocument"});
For LzMiniNode_DataNode_DOM, we need to do the same thing, get rid of
that static initialize method, and
just declare the setters the same way
static var setters:* =new LzInheritedHash({name1: val1, etc});
Then in any subclass you need to use the idiom of
static var setters = new LzInheritedHash(SUPERCLASS.setters);
to inherit the setters.
I haven't figured out a more automagic way to do this.
On Fri, Feb 1, 2008 at 11:37 AM, Philip Romanik
<promanik <at> laszlosystems.com> wrote:
>
> Hi Henry,
>
> There is code in the data classes that specify setters. For example, this
> code is in LzDataText.lzs:
>
> setters.data = "setData";
>
>
> Can this be done in a static initializer? The original traits use this
> method to install setters. The code compiles in swf9 but I don't know if it
> works. For example, in the class LzMiniNode_DataNode_DOM (my manually
> instantiated class):
>
> static function initialize (prototype) {
> // There will be no setters property in the trait prototype,
> // (and you don't want one there! as it would shadow the one
> // from LzNode) but it will be there after LzNode.initialize
> // runs
> if (prototype.hasOwnProperty('setters')) {
> // since you can't assign directly to these slots...
> // until LzNode.initialize has run
> prototype.setters.attributes = "setAttrs";
> prototype.setters.childNodes = "setChildNodes";
> prototype.setters.nodeName = "setNodeName";
> // Shouldn't be directly settable
> prototype.setters.ownerDocument = "setOwnerDocument";
>
>
> }
> }
>
>
>
>
> Yes, look at LaszloView.js or LzText.js for examples what I've been doing. I
> declare static class vars like this, which make copies of the superclass's
> setters vars
>
> static var getters = new LzInheritedHash(LFCNode.getters);
> static var defaultattrs = new LzInheritedHash(LFCNode.defaultattrs);
> static var options = new LzInheritedHash(LFCNode.options);
> static var setters = new LzInheritedHash(LFCNode.setters);
> static var __LZdelayedSetters:* = new
> LzInheritedHash(LFCNode.__LZdelayedSetters);
> static var earlySetters:* = new LzInheritedHash(LFCNode.earlySetters);
>
> And the base constructor in LFCNode (which is the 'static' version of
> LzNode, see core/LzNode.js) automatically copies these class vars to the
> corresponding instance vars when a node is constructed.
>
>
> Note, there's an issue at runtime that comes up if you have code which
> tries to set arbitrary properties on a class which have not been declared at
> compile time. To allow this, the class has to be declared 'dynamic'.
> Eventually we're going to make <attribute> declarations cause compile-time
> declarations of instance vars, but we don't do that yet so I've been doing
> the following thing:
>
> I have an idiom I am using in LzNode and LzView whereby I have an
> "internal" class, LFCNode, or LFCView, which is not declared 'dynamic', and
> then I have a kind of 'wrapper' class which I declare as 'dynamic', (e.g.,
> LzNode, LzView). This is to get the (hoped for) benefit of the as3 compiler
> making more efficient code for accessors to methods and instance vars of
> these superclasses because they are not declared dynamic.
>
> For the data classes, I think they can all just be left as they are, and
> not declare them dynamic, and see if we can get them to compile.
> For now if something subclasses LzNode, just leave it doing that.
> Eventually we may want to make that subclass LFCNode instead. At runtime,
> if we discover that there are classes where code which is adding properties
> dynamically at runtime, we can see about making a 'dynamic' subclass for
> those classes, or just declare them dynamic, or something.
>
>
>
>
> On Fri, Feb 1, 2008 at 10:27 AM, Philip Romanik <
> promanik <at> laszlosystems.com> wrote:
> > Hi Henry,
> >
> > What is the "new" way to handle setters in swf9? The solution you're
> > using in LaszloView looks like,
> >
> > static var setters = new LzInheritedHash(LFCNode.setters); ...
> > LFCView.setters.clip = -1;
> >
> >
> > Should I use this same approach with the files I'm porting?
> >
> > Thanks!
> >
> > Phil
> >
> >
>
>
>
> --
> Henry Minsky
> Software Architect
> hminsky <at> laszlosystems.com
--
--
Henry Minsky
Software Architect
hminsky <at> laszlosystems.com