2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('datasource-polling', function (Y, NAME) {
11 * Extends DataSource with polling functionality.
14 * @submodule datasource-polling
18 * Adds polling to the DataSource Utility.
20 * @extends DataSource.Local
26 Pollable.prototype = {
29 * @property _intervals
30 * @description Hash of polling interval IDs that have been enabled,
31 * stored here to be able to clear all intervals.
37 * Sets up a polling mechanism to send requests at set intervals and
38 * forward responses to given callback.
41 * @param msec {Number} Length of interval in milliseconds.
42 * @param [request] {Object} An object literal with the following properties:
44 * <dt><code>request</code></dt>
45 * <dd>The request to send to the live data source, if any.</dd>
46 * <dt><code>callback</code></dt>
47 * <dd>An object literal with the following properties:
49 * <dt><code>success</code></dt>
50 * <dd>The function to call when the data is ready.</dd>
51 * <dt><code>failure</code></dt>
52 * <dd>The function to call upon a response failure condition.</dd>
53 * <dt><code>argument</code></dt>
54 * <dd>Arbitrary data payload that will be passed back to the success and failure handlers.</dd>
57 * <dt><code>cfg</code></dt>
58 * <dd>Configuration object, if any.</dd>
60 * @return {Number} Interval ID.
62 setInterval: function(msec, request) {
63 var x = Y.later(msec, this, this.sendRequest, [ request ], true);
64 this._intervals[x.id] = x;
65 // First call happens immediately, but async
66 Y.later(0, this, this.sendRequest, [request]);
71 * Disables polling mechanism associated with the given interval ID.
73 * @method clearInterval
74 * @param id {Number} Interval ID.
76 clearInterval: function(id, key) {
77 // In case of being called by clearAllIntervals()
79 if(this._intervals[id]) {
81 this._intervals[id].cancel();
83 delete this._intervals[id];
88 * Clears all intervals.
90 * @method clearAllIntervals
92 clearAllIntervals: function() {
93 Y.each(this._intervals, this.clearInterval, this);
97 Y.augment(Y.DataSource.Local, Pollable);
100 }, '3.13.0', {"requires": ["datasource-local"]});