doLater.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. define("dojox/timing/doLater", ["./_base"], function(dxt){
  2. dojo.experimental("dojox.timing.doLater");
  3. /*=====
  4. var dxt = dojox.timing;
  5. =====*/
  6. dxt.doLater = function(/*anything*/conditional,/*Object ?*/context, /* Number ? */interval){
  7. // summary:
  8. // Check if a parameter is ready, and if not,
  9. // "do later". doLater will ping the parameter
  10. // until it evaluates to something (truthy).
  11. // It thens calls the caller with original
  12. // arguments, using the supplied context or
  13. // window.
  14. // description:
  15. // dojox.timing.doLater(conditional) is testing if the call
  16. // should be done later. So it returns
  17. // true if the param is false.
  18. // arguments:
  19. // conditional: anything
  20. // Can be a property that eventually gets set, or
  21. // an expression, method... anything that can be
  22. // evaluated.
  23. // context: Object
  24. // The namespace where the call originated.
  25. // Defaults to global and anonymous functions
  26. // interval: Number
  27. // Poll time to check conditional in Milliseconds
  28. // example:
  29. // | setTimeout(function(){
  30. // | if(dojox.timing.doLater(app.ready)){return;}
  31. // | console.log("Code is ready! anonymous.function SUCCESS")
  32. // | },700);
  33. //
  34. if(conditional){ return false; } // Boolean
  35. var callback = dxt.doLater.caller,
  36. args = dxt.doLater.caller.arguments;
  37. interval = interval || 100;
  38. context = context || dojo.global;
  39. setTimeout(function(){
  40. callback.apply(context, args);
  41. },interval);
  42. return true; // Boolean
  43. };
  44. return dxt.doLater;
  45. });