3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('loader-rollup', function(Y) {
10
* Optional automatic rollup logic for reducing http connections
11
* when not using a combo service.
17
* Look for rollup packages to determine if all of the modules a
18
* rollup supersedes are required. If so, include the rollup to
19
* help reduce the total number of connections required. Called
20
* by calculate(). This is an optional feature, and requires the
21
* appropriate submodule to function.
26
Y.Loader.prototype._rollup = function() {
27
var i, j, m, s, r = this.required, roll,
28
info = this.moduleInfo, rolled, c, smod;
30
// find and cache rollup modules
31
if (this.dirty || !this.rollups) {
34
if (info.hasOwnProperty(i)) {
35
m = this.getModule(i);
36
// if (m && m.rollup && m.supersedes) {
43
this.forceMap = (this.force) ? Y.Array.hash(this.force) : {};
46
// make as many passes as needed to pick up rollup rollups
50
// go through the rollup candidates
51
for (i in this.rollups) {
52
if (this.rollups.hasOwnProperty(i)) {
53
// there can be only one, unless forced
54
if (!r[i] && ((!this.loaded[i]) || this.forceMap[i])) {
55
m = this.getModule(i);
56
s = m.supersedes || [];
59
// @TODO remove continue
66
// check the threshold
67
for (j = 0; j < s.length; j++) {
70
// if the superseded module is loaded, we can't
71
// load the rollup unless it has been forced.
72
if (this.loaded[s[j]] && !this.forceMap[s[j]]) {
75
// increment the counter if this module is required.
76
// if we are beyond the rollup threshold, we will
77
// use the rollup module
78
} else if (r[s[j]] && m.type == smod.type) {
80
// Y.log("adding to thresh: " + c + ", " + s[j]);
81
roll = (c >= m.rollup);
83
// Y.log("over thresh " + c + ", " + s[j]);
90
// Y.log("adding rollup: " + i);
95
// expand the rollup's dependencies
102
// if we made it here w/o rolling up something, we are done
110
}, '3.4.1' ,{requires:['loader-base']});