~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/build/loader-rollup/loader-rollup-debug.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

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