source: Dev/branches/rest-dojo-ui/client/dojox/timing/doLater.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.5 KB
Line 
1define(["./_base"], function(dxt){
2        dojo.experimental("dojox.timing.doLater");
3/*=====
4var 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               
40                setTimeout(function(){
41                        callback.apply(context, args);
42                },interval);
43                return true; // Boolean
44        };
45        return dxt.doLater;
46});
Note: See TracBrowser for help on using the repository browser.