5
<title>Example: DataSource with Polling</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Example: DataSource with Polling</h1>
19
<div id="main" class="yui3-u">
20
<div class="content"><style scoped>
21
/* custom styles for this example */
22
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
26
<p>DataSource's Pollable extension enables polling functionality on all your DataSource instances.</p>
29
<div class="example yui3-skin-sam">
31
<h6>Poll every second for current time:</h6>
32
<input type="button" id="demo_enable" value="Start polling">
33
<input type="button" id="demo_disable" value="End polling">
34
<div id="demo_output_polling" class="output"></div>
37
<script type="text/javascript">
38
YUI().use("dump", "node", "datasource-function", "datasource-polling", function (Y) {
40
myFunction = function() {
43
myDataSource = new Y.DataSource.Function({source:myFunction}),
47
Y.one("#demo_output_polling")
48
.setContent("At the tone the time will be: " +
49
Y.dump(e.response.results[0].toString()));
52
Y.one("#demo_output_polling")
53
.setContent("Could not retrieve data: " + e.error.message);
58
Y.on("click", function(e){
60
myDataSource.clearInterval(id);
62
id = myDataSource.setInterval(1000, request);
65
Y.on("click", function(e){
66
myDataSource.clearInterval(id);
73
<p>Include the <code>datasource-pollable</code> extension in your <code>Y.use()</code> statement to add the <code>setInterval()</code>, <code>clearInterval()</code>, and <code>clearAllInterval()</code> methods to all your DataSource instances.</p>
75
<pre class="code prettyprint">YUI().use("datasource-function", "datasource-polling", function(Y) {
76
var myFunction = function() {
79
myDataSource = new Y.DataSource.Function({source:myFunction}),
83
Y.one("#demo_output_polling")
84
.setContent("At the tone the time will be: " +
85
Y.dump(e.response.results[0].toString()));
88
Y.one("#demo_output_polling")
89
.setContent("Could not retrieve data: " + e.error.message);
93
id = myDataSource.setInterval(1000, request); // Starts polling
95
myDataSource.clearInterval(id); // Ends polling
101
<div id="sidebar" class="yui3-u">
105
<div class="sidebox">
107
<h2 class="no-toc">Examples</h2>
111
<ul class="examples">
114
<li data-description="The Local DataSource manages retrieval of in-page data, from JavaScript arrays and objects to DOM elements.">
115
<a href="datasource-local.html">DataSource.Local</a>
120
<li data-description="The Get DataSource, which manages retrieval of data from remote sources via the Get Utility, can be useful for accessing data from cross-domain servers without the need for a proxy.">
121
<a href="datasource-get.html">DataSource.Get</a>
126
<li data-description="The IO DataSource manages retrieval of data from remote sources, via the IO Utility.">
127
<a href="datasource-io.html">DataSource.IO</a>
132
<li data-description="The Function DataSource, which manages retrieval of data from a JavaScript function, provides a highly customizeable mechanism for implementer-defined data retrieval algorithms">
133
<a href="datasource-function.html">DataSource.Function</a>
138
<li data-description="Use the DataSourceCache plugin to enable caching and reduce server calls to remote sources.">
139
<a href="datasource-caching.html">DataSource with Caching</a>
144
<li data-description="The DataSourceCache plugin supports offline caching so that cached data persists across browser sessions.">
145
<a href="datasource-offlinecache.html">DataSource with Offline Cache</a>
150
<li data-description="Use the Pollable extension to enable polling in your DataSource.">
151
<a href="datasource-polling.html">DataSource with Polling</a>
163
<div class="sidebox">
165
<h2 class="no-toc">Examples That Use This Component</h2>
169
<ul class="examples">
186
<li data-description="How to provide autocomplete suggestions using a DataSource instance.">
187
<a href="../autocomplete/ac-datasource.html">Remote Data via DataSource</a>
199
<script src="../assets/vendor/prettify/prettify-min.js"></script>
200
<script>prettyPrint();</script>