Cross Reference: /yui3/src/datasource/docs/datasource-polling.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<style scoped>
/* custom styles for this example */
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
</style>
<div class="intro">
<p>DataSource's Pollable extension enables polling functionality on all your DataSource instances.</p>
</div>
<div class="example yui3-skin-sam">
{{>datasource-polling-source}}
</div>
<p>Include the `datasource-pollable` extension in your `Y.use()` statement to add the `setInterval()`, `clearInterval()`, and `clearAllInterval()` methods to all your DataSource instances.</p>
```
YUI().use("datasource-function", "datasource-polling", function(Y) {
var myFunction = function() {
return new Date();
},
myDataSource = new Y.DataSource.Function({source:myFunction}),
request = {
callback: {
success: function(e){
Y.one("#demo_output_polling")
.setContent("At the tone the time will be: " +
Y.dump(e.response.results[0].toString()));
},
failure: function(e){
Y.one("#demo_output_polling")
.setContent("Could not retrieve data: " + e.error.message);
}
}
},
id = myDataSource.setInterval(1000, request); // Starts polling
myDataSource.clearInterval(id); // Ends polling
});
```