The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 15, 2019, 06:49:00 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Transmit State Class  (Read 1754 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« on: May 07, 2007, 02:47:28 PM »

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:
Code:
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:

Code:
// ----------------------------------------------------------- //
//                       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
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!