datasource-polling.js revision aa654579cf9c3726db8672b7f090467332fc1ad6
/**
* Extends DataSource with polling functionality.
*
* @module datasource
* @submodule datasource-polling
*/
/**
* Adds polling to the YUI DataSource utility.
* @class Pollable
* @extends DataSource.Local
*/
Pollable = function() {};
/**
* @property _intervals
* @description Array of polling interval IDs that have been enabled,
* stored here to be able to clear all intervals.
* @private
*/
_intervals: null,
/**
* Sets up a polling mechanism to send requests at set intervals and forward
* responses to given callback.
*
* @method setInterval
* @param msec {Number} Length of interval in milliseconds.
* @param request {Object} Request object.
* @param callback {Object} An object literal with the following properties:
* <dl>
* <dt><code>success</code></dt>
* <dd>The function to call when the data is ready.</dd>
* <dt><code>failure</code></dt>
* <dd>The function to call upon a response failure condition.</dd>
* <dt><code>scope</code></dt>
* <dd>The object to serve as the scope for the success and failure handlers.</dd>
* <dt><code>argument</code></dt>
* <dd>Arbitrary data that will be passed back to the success and failure handlers.</dd>
* </dl>
* @return {Number} Interval ID.
*/
Y.log("Enabling polling to live data for \"" + Y.dump(request) + "\" at interval " + msec, "info", this.toString());
var self = this,
id = setInterval(function() {
//self._makeConnection(request, callback);
}, msec);
if(!this._intervals) {
this._intervals = [];
}
return id;
}
else {
Y.log("Could not enable polling to live data for \"" + Y.dump(request) + "\" at interval " + msec, "info", this.toString());
}
},
/**
* Disables polling mechanism associated with the given interval ID.
*
* @method clearInterval
* @param id {Number} Interval ID.
*/
clearInterval: function(id) {
// Remove from tracker if there
var tracker = this._intervals || [],
for(; i>-1; i--) {
}
}
},
/**
* Clears all intervals.
*
* @method clearAllIntervals
*/
clearAllIntervals: function() {
var tracker = this._intervals,
for(; i>-1; i--) {
clearInterval(tracker[i]);
}
this._intervals = [];
}
};