This little class is of very little use except to folks that want to use the Ajax Requestor Class and track the master status of requestors on a page.
All you really do is create one of these and create a function to receive the callback (onChange) - then set <this object> as the masterStatus on an Ajax Requestor. Then, whenever a requestor goes busy, or more precisely, when the current page goes from none-busy to at-least-one-busy you'll get called on the onChange event with (true) - then when the page goes from more-than-zero-busy to zero you'll get another callback on onChange as (false). This is specifically here for my article on the Argument Against Ajax.
An example:
state = new transmitState();
state.onChange = handleStateChange;
ajax1 = new ajaxRequestor();
ajax1.masterState = state;
...
function handleStateChange(newState)
{
if (newState)
{
// Do "We're just now busy" things
} else {
// Do "We're now idle" things
}
}
There's obviously more to throwing the request than that, but this shows how the two are connected. Here's the actual class:
// ----------------------------------------------------------- //
// transmitState //
// ----------------------------------------------------------- //
function transmitState() { this.clear(); }
transmitState.prototype.clear = function()
{
this.busyCount = 0;
this.onChange = null;
this.busy = false;
}
transmitState.prototype.handleChange = function(busy)
{
if (busy) { this.busyCount++; }
if (!busy) { this.busyCount--; }
if (this.busyCount < 0) { this.busyCount = 0; }
if (this.busyCount)
{
if (!this.busy) { if (this.onChange) { this.onChange(true); } }
this.busy = true;
} else {
if (this.busy) { if (this.onChange) { this.onChange(false); } }
this.busy = false;
}
}
/p