I was wondering if I could get your expert opinions on pro's/cons of using this solution?

What the below code does is effectively remove multiple repetitve calls within objects that in a nutshell aren't necessary. An example would be:

Component:
Window Componet

Ingredients:
2x SingleBevelPanel components


Inside the Window Component, it basically has a layoutChildren method which looks like this


Window.prototype.layoutChildren = function() {
.. Internal logic here…
    TitleBarLayer.setSize(tb.w,tb.h);
    TitleBarLayer.moveTo(tb.x,tb.y);
    BodyLayer.setSize(tb.w, tb.h);
    BodyLayer.moveTo(tb.x, tb.y);
}


Now the TitleBarLayer & BodyLayer are local variables that represent the SingleBevelPanel component, and basically they both make some metric modifications internally, which then result in an internal "draw()" call for each method (setSize/moveTo).


Now as you can guess, the construction of the Window component would result in 4 redraw calls alone for the SingleBevelPanel, which to me seems un-needed. So what I have got below is a doLater() method, which basically appends the required actions to a que, it will then check to see if that method exists in the que, if it does, ignore it (unless over-ridden manually). It will then process the que 1ms after the JS Thread has completed its intial construction (which I dunno, 1ms to the end user wouldn't even register?).

This concept seems to work in my favour as I reduced un-needed method calls? I had a situation where the debug was something like this:

--------: --------- START INDEX.CFM ----------
Window: createChildren()
SingleBevelPanel: Draw()
SingleBevelPanel: Draw()
Window: attachTo()
Window: draw()
Window: applyProperties()
Window: measure()
Window: layoutChildren()
SingleBevelPanel: Draw()
SingleBevelPanel: Draw()
--------: --------- END INDEX.CFM ----------
Window: draw()
Window: applyProperties()
Window: measure()
Window: layoutChildren()
SingleBevelPanel: Draw()
SingleBevelPanel: Draw()
SingleBevelPanel: Draw()
SingleBevelPanel: Draw()


To which its now: --------: --------- START INDEX.CFM ---------- Window: createChildren() Window: attachTo() --------: --------- END INDEX.CFM ---------- Window: draw() Window: applyProperties() Window: measure() Window: layoutChildren() SingleBevelPanel: Draw() SingleBevelPanel: Draw()





Code Block is:
(all components extend UIComponent).
----------------
UIComponent.prototype.doLater = function(obj,fn,isOverride) {
        if (this.methodTable == undefined) {
                this.methodTable = new Array();
        }
        var localObj = new Object();
        var controller = this;
        var isFound = false;

        localObj.dispatch = function() {
            controller.doLaterDispatcher();
        }

for(var i=0; i < this.methodTable.length; i++) {
isFound = false;
if(this.methodTable[i].obj == obj && this.methodTable[i].fn == fn) {
isFound = true;
break;
}
}
if(!isFound || isOverride) {
this.methodTable.push({obj:obj, fn:fn});
}


        if(_global.onEnterFrame == undefined) {
            _global.onEnterFrame = window.setInterval(localObj.dispatch,1);
        }
};

UIComponent.prototype.doLaterDispatcher = function(obj,fn) {

        window.clearInterval(_global.onEnterFrame)
        delete _global.onEnterFrame;
        // invalidation comes first
        if (this.invalidateFlag) {
            this.draw();
        }

// make a copy of the methodtable so methods called can requeue themselves w/o putting
// us in an infinite loop


        var __methodTable = this.methodTable;
        // new doLater calls will be pushed here
        //this.methodTable = new Array();

        // now do everything else
        if (__methodTable.length > 0)    {
            var m
            while((m = __methodTable.shift()) != undefined) {
                m.obj[m.fn]();
            }
        }
        this.methodTable = new Array();
};




--

Regards,
Scott Barnes
-
http://www.mossyblog.com
http://www.bestrates.com.au

---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to