Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 'use strict'; | |
gary.poster
2013/02/25 21:20:05
Please add the yuidoc @module stuff here (see the
jeff.pihach
2013/02/25 21:46:59
will fix
| |
2 | |
3 YUI.add('app-subapp-extension', function(Y) { | |
4 | |
5 function SubAppRegistration() {} | |
gary.poster
2013/02/25 21:20:05
Please add a @class directive like the topology ex
jeff.pihach
2013/02/25 21:46:59
will fix
| |
6 | |
7 SubAppRegistration.ATTRS = { | |
8 subApps: { | |
9 value: {} | |
10 } | |
11 }; | |
12 | |
13 SubAppRegistration.prototype = { | |
14 | |
15 /** | |
16 A list of sub applications to be instantiated after initialization | |
17 of the parent app. | |
18 | |
19 [{ | |
20 type: Y.SubappInstance | |
21 config: {} | |
22 }] | |
23 | |
24 @property subApplications | |
25 @type {array} | |
gary.poster
2013/02/25 21:20:05
We usually comment these with "*" marks before eac
jeff.pihach
2013/02/25 21:46:59
YUIdoc doesn't require them it simply requires two
| |
26 */ | |
27 subApplications: [], | |
28 | |
29 /** | |
30 Adds all of the sub applications listed in the subApplications property. | |
31 | |
32 @method addSubApplications | |
33 */ | |
34 addSubApplications: function() { | |
35 this.addSubApps(this.subApplications); | |
36 }, | |
37 | |
38 /** | |
39 Adds the sub application and it's routes to the parent application. | |
gary.poster
2013/02/25 21:20:05
typo: its
jeff.pihach
2013/02/25 21:46:59
will fix
| |
40 | |
41 @method addSubApp | |
42 @param {string} subApp string referance to an instantiable Y.App object. | |
gary.poster
2013/02/25 21:20:05
typo: reference
I don't understand this comment.
jeff.pihach
2013/02/25 21:46:59
My thought process behind this was that I wanted t
gary.poster
2013/02/25 21:59:00
Ah I thought juju was not off of Y. All's well th
| |
43 @param {object} config configuration properties for the subapp. | |
44 */ | |
45 addSubApp: function(subApp, config) { | |
46 var SubAppObject = Y.Object.getValue(Y, subApp.split('.')), | |
47 subApps = this.get('subApps'), | |
48 routes; | |
49 | |
50 subApp = new SubAppObject(config); | |
51 | |
52 subApps[subApp.get('urlNamespace')] = subApp; | |
53 | |
54 routes = this._extractRoutes(subApp); | |
55 | |
56 this._augmentParentRoutes(routes); | |
57 }, | |
58 | |
59 /** | |
60 Wrapper for addSubApp to add multiple sub apps at once. | |
61 | |
62 [{ | |
63 app: Y.SubAppOne, | |
64 cfg: {} | |
65 }] | |
66 | |
67 @method addSubApps | |
68 @param {array} subApps an array of sub abb objects and configs. | |
69 */ | |
70 addSubApps: function(subApps) { | |
71 for (var i = 0; i < subApps.length; i += 1) { | |
72 this.addSubApp(subApps[i].type, subApps[i].config); | |
73 } | |
74 }, | |
75 | |
76 /** | |
77 Public method to refresh routes from the sub apps. | |
gary.poster
2013/02/25 21:20:05
When would you need to call this?
jeff.pihach
2013/02/25 21:46:59
If you manipulated the routes on a subapp after in
gary.poster
2013/02/25 21:59:00
Heh, cool. I suggest removing it then. When you
| |
78 | |
79 @method refreshRoutes | |
80 @param {integer} index index of the subapp to refresh if undefined | |
gary.poster
2013/02/25 21:20:05
typo: s/index index/index/
...to refresh. If und
jeff.pihach
2013/02/25 21:46:59
will fix
| |
81 it will refresh all. | |
82 @return {array} array of sub app route data. | |
83 */ | |
84 refreshRoutes: function(index) { | |
85 return this._augmentParentRoutes(this._extractRoutes(index)); | |
86 }, | |
87 | |
88 /** | |
89 Extract the routes out of the sub apps. | |
90 | |
91 @method _extractRoutes | |
92 @protected | |
93 @param {object | integer | undefined} subApp will extract the routes | |
94 out of the supplied subApp, index, or all subApps if undefined. | |
95 @return {array} array of sub app route data. | |
96 */ | |
97 _extractRoutes: function(subApp) { | |
98 var subApps = this.get('subApps'), | |
99 routes, subRoutes, i, j; | |
100 | |
101 switch (typeof subApp) { | |
102 case 'number': | |
gary.poster
2013/02/25 21:20:05
Is there really a use case for this? Seems like a
jeff.pihach
2013/02/25 21:46:59
The idea behind allowing the dev to specify a numb
gary.poster
2013/02/25 21:59:00
Huh, ok. I suggest either giving a believable exa
| |
103 subApp = subApps[subApp]; | |
104 /* falls through */ | |
105 case 'object': | |
106 routes = subApp.getSubAppRoutes(); | |
107 break; | |
108 | |
109 case 'undefined': | |
gary.poster
2013/02/25 21:20:05
Sometimes we have a default case that throws an er
jeff.pihach
2013/02/25 21:46:59
Sorry I don't follow - are you saying that we shou
gary.poster
2013/02/25 21:59:00
No, just a "default:" that throws an error
| |
110 routes = []; | |
111 for (i = 0; i < subApps.length; i += 1) { | |
112 subRoutes = subApps[i].getSubAppRoutes(); | |
gary.poster
2013/02/25 21:20:05
Is getSubAppRoutes the thing that is responsible f
jeff.pihach
2013/02/25 21:46:59
yes getSubAppRoutes fetches its routes and adds it
gary.poster
2013/02/25 21:59:00
+1 on not clobbering. I was talking about having
| |
113 for (j = 0; j < subRoutes.length; j += 1) { | |
114 routes.push(subRoutes[j]); | |
115 } | |
116 } | |
117 break; | |
118 } | |
119 return routes; | |
120 }, | |
121 | |
122 /** | |
123 Adds the sub app routes to the parent routes after the middleware | |
124 | |
125 @method _augmentParentRoutes | |
126 @protected | |
127 @param {array} array of route objects. | |
128 */ | |
129 _augmentParentRoutes: function(routes) { | |
130 var parentRoutes = this.get('routes'), | |
131 middlewareIndex, groupedRoutes; | |
132 | |
133 Y.Array.some(parentRoutes, function(value, index, array) { | |
134 if (value.path !== '*') { | |
gary.poster
2013/02/25 21:20:05
hm. I guess this is a reasonable definition of mi
jeff.pihach
2013/02/25 21:46:59
Maybe I should comment this further - what it's do
gary.poster
2013/02/25 21:59:00
Yeah, I understood most of that. That's not a rob
bcsaller
2013/02/26 02:00:54
While native Y.App.route doesn't support annotatio
| |
135 middlewareIndex = index; | |
136 return true; | |
137 } | |
138 }); | |
139 | |
140 routes.unshift(middlewareIndex, 0); | |
141 Array.prototype.splice.apply(parentRoutes, routes); | |
142 | |
143 this.set('routes', parentRoutes); | |
144 } | |
145 }; | |
146 | |
147 Y.namespace('juju').SubAppRegistration = SubAppRegistration; | |
148 | |
149 }, '0.1.0'); | |
OLD | NEW |