The docs for Dojo's AMD loader mention a tracing API. Are there any examples of how this is implemented?
I would like to leverage it to show a "Loaded X of X" style message while my app's various dependencies are loaded but I'm not sure how to do so or where to including the tracing in the flow of my code.
Edit: It seems that the trace API is only available on the source version of Dojo. Is there a different way of achieving what I want?
This code seems to work but it's too brittle. It relies on 1) require exposing it's inner workings in a source version of Dojo and 2) properties of require that may change in future. Surely there's a better way!
require( [], function()
{
// output amd progress
var loadWatchHandle = setInterval( function()
{
var all = Object.keys( require.modules ).length,
waiting = 0;
for( dep in require.waiting )
{
if( require.waiting[ dep ] !== 1 )
{
waiting++;
}
}
// write progress
console.log( ( all - waiting ) + '/' + all + ' files (' + parseInt( ( all - waiting ) / all * 100 ) + '%)' );
}, 50 );
require( [ 'dojo/parser',
'dojo/ready',
'dijit/layout/BorderContainer',
'squad_builder/TabContainer',
'dijit/layout/ContentPane',
'dojo/domReady!' ],
function( parser, ready )
{
parser.parse();
ready( function() // uses ready not domReady because we want initial djits to be parsed
{
// stop tracing
clearInterval( loadWatchHandle );
// bootstrap here...
} );
} );
} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With