Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. var Poll = function(pollFunction, intervalTime) {
  2. var intervalId = null;
  3.  
  4. this.start = function(newPollFunction, newIntervalTime) {
  5. pollFunction = newPollFunction || pollFunction;
  6. intervalTime = newIntervalTime || intervalTime;
  7.  
  8. if ( intervalId ) {
  9. this.stop();
  10. }
  11.  
  12. intervalId = setInterval(pollFunction, intervalTime);
  13. };
  14.  
  15. this.stop = function() {
  16. clearInterval(intervalId);
  17. };
  18. };
  19.  
  20. var p = new Poll(function() { console.log("hi!"); }, 1000);
  21. p.start();
  22. setTimeout(function() { p.stop();}, 5000);
  23.  
  24. var p = new Poll(sendRequest, 3000);
  25. p.start();
  26.  
  27. dojo.provide("Poll");
  28.  
  29. dojo.declare("Poll", null, {
  30. intervalId: null,
  31. pollFunction: null,
  32. intervalTime: null,
  33.  
  34. constructor: function(newPollFunction, newIntervalTime) {
  35. this.pollFunction = newPollFunction;
  36. this.intervalTime = newIntervalTime;
  37. },
  38.  
  39. start: function(newPollFunction, newIntervalTime) {
  40. this.pollFunction = newPollFunction || this.pollFunction;
  41. this.intervalTime = newIntervalTime || this.intervalTime;
  42.  
  43. this.stop();
  44. this.intervalId = setInterval(this.pollFunction, this.intervalTime);
  45. },
  46.  
  47. stop: function() {
  48. clearInterval(this.intervalId);
  49. }
  50. });
  51.  
  52. var p = new Poll(function() {console.log("hi");}, 250);
  53. p.start();
  54. setTimeout(dojo.hitch(p, p.stop), 1000);
  55.  
  56. yourGrid.on('dgrid-refresh-complete', function(event) {
  57.  
  58. //Ajax request fireing every 3 sec
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement