ExtJS Loader Success Callback Source

Source: Internet
Author: User


First, loader has several important attributes.

Queue: [] holds all Master file class information, including his dependent file information, as follows: [{requires: ' Seed.view.MainGrid ' callback:callback//Loader. Require (Dependencies,function () {}); Note: All dynamically loaded file information will be placed in the queue isloading: Loading numloadedfiles: The number of completed files has been loaded n Umpendingfiles: Number of items to load seriptsloading: number of files being loaded isclassfileloaded: {} object stores all classes and whether they have been loaded


The callback method is called when the file is loaded, parsing is complete:

if  (' AddEventListener '  in script )  {                 script.onload = onLoadFn;             } else if  (' readyState '  in script)  {   // for <IE9 Compatability                 script.onreadystatechange = function ()  {                      if  ( this.readyState ==  ' Loaded '  | |  this.readyState ==  ' complete '  )  {         &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ONLOADFN ();                     }                 };             } else {                  script.onload = onLoadFn;             }



Callback methods, which were previously involved, are as follows:

Onfileloaded: function (Classname, filepath)  {         Whether the     var loaded = isClassFileLoaded[className]; //  file has been loaded             Loader.numLoadedFiles++; //  Loaded quantity plus 1            isclassfileloaded[classname]  = true; //  tagged file has been loaded              isFileLoaded[filePath] = true;             // In FF, when we sync load something that has  had a script tag inserted, the load event may             // sometimes fire even if we  Clean it up and&nbSp;set it to null, so check if we ' Re already loaded here.             if  (!loaded)  { //  If the file has not been loaded before, then the load count minus 1                 loader.numpendingfiles--;            }             if  (loader.numpendingfiles = == 0)  { //  when the number to load is 0                 loader.refreshqueue ();           Treatment of   }            // missingclasses , slightly         }



When the number to load is 0, execute loader.refreshqueue (), as follows:

Refreshqueue: function ()  {             var ln = queue.length,                 i, item, j, requires;             // When the queue of loading classes reaches  Zero, trigger readiness            if   (!ln && ! loader.scriptsloading)  { // , recursive end condition: Load queue is empty                  return loader.triggerready (); //  Triggerready See below             }             for  (i = 0; i < ln;  i++) &NBsp { //  each object in a looping queue                  item = queue[i];                 if  (item)  {                     requires = item.requires;                     //  don ' t bother checking when the number of files loaded                      // is still less than the array length                     if  ( Requires.length > loAder.numloadedfiles)  {                         continue;                     }                     //  remove any required classes that are loaded                     for  (j = 0;  j < requires.length; )  {                         if  ( Manager.iscreated (Requires[j])  { //  If a dependency class A of item is already created, remove it from the require of item                               // Take out from the queue                              arrayerase (requires, j, 1);                         }                          else {                             j++;                          }                    }                      // if we ' Ve ended up with no required classes, call  the callback                     if  (item.requires.length === 0)  { //  When all dependent files for a class have been loaded, remove the item              from the queue            arrayerase (queue, i, 1);                          item.callback.call (Item.scope);                         loader.refreshqueue ();//  recursion                           break;                     }                 }            }             return Loader;         }



The function of the Refreshqueue () method is to keep the loop detection until all classes are loaded, executed, created, and then called the Triggerready () method, as follows:

Triggerready: function ()  {             var listener,                 refClasses = usedClasses;              if  (loader.isloading)  {                 Loader.isLoading = false;                 if  (refclasses.length !== 0)  {  //  load the path referenced with the USE keyword                      // Clone then empty the array to  eliminate potential recursive loop issue              &Nbsp;      refclasses = refclasses.slice ();                      usedclasses.length = 0;                     // this may immediately call us  back if all  ' uses '  classes                     // have been loaded                      Loader.require (Refclasses, loader.triggerready, loader);                     return Loader;                 }             }            ext.array.sort (ReadyListeners,  comparepriority);// listener sort              // this method can be called with Loader.isLoading either  true or false            //  (CAN  be called with false when all  ' uses '  classes are already  loaded)             // this may  bypass the above if condition             while  (readylisteners.length && ! loader.isloading)  { //  Call callback method &NBSP;&NBSP;&NBSP;&Nbsp;            // calls to  refreshqueue may re-enter triggerready                 // so we cannot necessarily iterate  the readylisteners array                 listener = readylisteners.shift ();                 listener.fn.call (Listener.scope);             }             return loader;        }


It can be seen from this that the USE keyword relies on classes that are loaded only when other keyword-dependent classes are loaded successfully.





This article is from the "Technology Life" blog, please be sure to keep this source http://wangyuelucky.blog.51cto.com/1011508/1604695

ExtJS Loader Success Callback Source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.