[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/loader-rollup/ -> loader-rollup.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('loader-rollup', function (Y, NAME) {
   9  
  10  /**
  11   * Optional automatic rollup logic for reducing http connections
  12   * when not using a combo service.
  13   * @module loader
  14   * @submodule rollup
  15   */
  16  
  17  /**
  18   * Look for rollup packages to determine if all of the modules a
  19   * rollup supersedes are required.  If so, include the rollup to
  20   * help reduce the total number of connections required.  Called
  21   * by calculate().  This is an optional feature, and requires the
  22   * appropriate submodule to function.
  23   * @method _rollup
  24   * @for Loader
  25   * @private
  26   */
  27  Y.Loader.prototype._rollup = function() {
  28      var i, j, m, s, r = this.required, roll,
  29          info = this.moduleInfo, rolled, c, smod;
  30  
  31      // find and cache rollup modules
  32      if (this.dirty || !this.rollups) {
  33          this.rollups = {};
  34          for (i in info) {
  35              if (info.hasOwnProperty(i)) {
  36                  m = this.getModule(i);
  37                  // if (m && m.rollup && m.supersedes) {
  38                  if (m && m.rollup) {
  39                      this.rollups[i] = m;
  40                  }
  41              }
  42          }
  43      }
  44  
  45      // make as many passes as needed to pick up rollup rollups
  46      for (;;) {
  47          rolled = false;
  48  
  49          // go through the rollup candidates
  50          for (i in this.rollups) {
  51              if (this.rollups.hasOwnProperty(i)) {
  52                  // there can be only one, unless forced
  53                  if (!r[i] && ((!this.loaded[i]) || this.forceMap[i])) {
  54                      m = this.getModule(i);
  55                      s = m.supersedes || [];
  56                      roll = false;
  57  
  58                      // @TODO remove continue
  59                      if (!m.rollup) {
  60                          continue;
  61                      }
  62  
  63                      c = 0;
  64  
  65                      // check the threshold
  66                      for (j = 0; j < s.length; j++) {
  67                          smod = info[s[j]];
  68  
  69                          // if the superseded module is loaded, we can't
  70                          // load the rollup unless it has been forced.
  71                          if (this.loaded[s[j]] && !this.forceMap[s[j]]) {
  72                              roll = false;
  73                              break;
  74                          // increment the counter if this module is required.
  75                          // if we are beyond the rollup threshold, we will
  76                          // use the rollup module
  77                          } else if (r[s[j]] && m.type === smod.type) {
  78                              c++;
  79                              roll = (c >= m.rollup);
  80                              if (roll) {
  81                                  break;
  82                              }
  83                          }
  84                      }
  85  
  86                      if (roll) {
  87                          // add the rollup
  88                          r[i] = true;
  89                          rolled = true;
  90  
  91                          // expand the rollup's dependencies
  92                          this.getRequires(m);
  93                      }
  94                  }
  95              }
  96          }
  97  
  98          // if we made it here w/o rolling up something, we are done
  99          if (!rolled) {
 100              break;
 101          }
 102      }
 103  };
 104  
 105  
 106  }, '3.17.2', {"requires": ["loader-base"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1