From: Scott A. L. <sc...@sc...> - 2000-10-28 21:54:01
|
Yes, a boolean could do the same trick. Maybe removeChild/deleteChild can set it to true/false if the length becomes zero. My point is that when you define an object's prototype structure with another object, as in WidgetX, all of the properties of that base DynLayer instance are shared with each Widget. Widget.prototype=new DynLayer() <-- Widget.prototype is a new DynLayer *instance* This is generally okay in DynAPI2 because the shared properties are eventually overwritten with unique ones. For example, all WidgetX model widgets share the *same* css, elm and doc object when first constructed. But when you add them to a parent object, the assignElement method overwrites them with *unique* values. But children[] is never overwritten anywhere, so it remains a reference to the children array of the shared base DynLayer instance. So we either have to 1) always remember to assign it "manually" in our widget code, or 2) find a better place in the DynLayer code to assign it to ensure it is unique. I'm not trying to undermine the WidgetX model, because it's an easy way to achieve a sort of inheritance, but this issue needs to be addressed. Who knows what kind of memory leaks this may cause in the long run: Widget1.prototype = new DynLayer(); Widget2.prototype = new Widget1(); Widget3.prototype = new Widget2(); etc. scottandrew -----Original Message----- From: Robert Rainwater <rai...@us...> To: Scott Andrew LePera <dyn...@li...> Date: Saturday, October 28, 2000 2:13 PM Subject: Re: [Dynapi-Dev] (no subject) > >There's also a bit of inconsistency with making the children array >null. Because once you remove all the children, the array is not >null, but has a length of 0. So, in your widget, you will have to >check for a null array and a array of length 0. I don't understand >why the array can't be initialized to an empty array. > > >Later, >Robert <rai...@us...> > >> I think I've found a fix for the problem with children arrays being shared >> between widgets made with the widgetX model. >> >> The problem: >> >> Widget.prototype = new DynLayer() >> >> When this is done, the properties of the base DynLayer are *shared* with >> every Widget made with the constructor. >> >> Most of these shared properties are reassigned to unique ones when >> createElement is called on the Widget. However, the children array is not, >> and it gives the effect that all Widgets share the same children array. >> >> So I've posted a patch for DynLayer and DynDocument that assigns the >> this.children array only when you use addChild. DynLayer-based widgets >> won't have a children array until you add at least one child. >> >> I also made changes to removeChild, removeAllChildren, etc. that check for >> the existence of the child array before proceeding. >> >> This should ensure that the children array is a unique object for each >> widget, and not the common one in the Widget prototype. Then you can safely >> use WidgetX to simulate inheritance without the shared-properties problem. >> >> The only consideration is if you build a widget that manipulates the >> children array, you should test it it exists first (it's initially set to >> null until you use addChild). >> >> I've only tested it on a few IBS and GUI widgets, but it seems to work >> across the board. I've posted the patch for review. >> >> scottandrew >> >> >> >> >> >> >> ------ >> Scott Andrew LePera >> DHTML / Scripting / CGI and other neat stuff >> sc...@sc... >> http://www.scottandrew.com > > >_______________________________________________ >Dynapi-Dev mailing list >Dyn...@li... >http://lists.sourceforge.net/mailman/listinfo/dynapi-dev > |