forked from FabModules/fabmodules-html5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtree.js~
executable file
·73 lines (64 loc) · 1.57 KB
/
rtree.js~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Usage:
// Put this in a separate file and load it as the first module
// (See https://github.com/jrburke/requirejs/wiki/Internal-API:-onResourceLoad)
// Methods available after page load:
// rtree.map()
// - Fills out every module's map property under rtree.tree.
// - Print out rtree.tree in the console to see their map property.
// rtree.toUml()
// - Prints out a UML string that can be used to generate UML
// - UML Website: http://yuml.me/diagram/scruffy/class/draw
requirejs.onResourceLoad = function (context, map, depMaps) {
if (!window.rtree) {
window.rtree = {
tree: {},
map: function() {
for (var key in this.tree) {
if (this.tree.hasOwnProperty(key)) {
var val = this.tree[key];
for (var i =0; i < val.deps.length; ++i) {
var dep = val.deps[i];
val.map[dep] = this.tree[dep];
}
}
}
},
toUml: function() {
var uml = [];
for (var key in this.tree) {
if (this.tree.hasOwnProperty(key)) {
var val = this.tree[key];
for (var i = 0; i < val.deps.length; ++i) {
uml.push("[" + key + "]->[" + val.deps[i] + "]");
}
}
}
return uml.join("\n");
}
};
}
var tree = window.rtree.tree;
function Node() {
this.deps = [];
this.map = {};
}
if (!tree[map.name]) {
tree[map.name] = new Node();
}
// For a full dependency tree
if (depMaps) {
for (var i = 0; i < depMaps.length; ++i) {
tree[map.name].deps.push(depMaps[i].name);
}
}
// For a simple dependency tree
// if (map.parentMap && map.parentMap.name) {
// if (!tree[map.parentMap.name]) {
// tree[map.parentMap.name] = new Node();
// }
//
// if (map.parentMap.name !== map.name) {
// tree[map.parentMap.name].deps.push(map.name);
// }
// }
};