File tree 6 files changed +35
-10
lines changed
6 files changed +35
-10
lines changed Original file line number Diff line number Diff line change
1
+ < span > {{ctrl.data.value}}
2
+ < span ng-if ="ctrl.data.right != null "> < tree-url data =ctrl.data.right > </ span >
3
+ < span ng-if ="ctrl.data.left != null "> < tree-url data =ctrl.data.left > </ span >
4
+ </ span >
Original file line number Diff line number Diff line change @@ -19,6 +19,15 @@ class TreeComponent {
19
19
var data;
20
20
}
21
21
22
+ @Component (
23
+ selector: 'tree-url' ,
24
+ templateUrl: 'tree-tmpl.html' ,
25
+ publishAs: 'ctrl' )
26
+ class TreeUrlComponent {
27
+ @NgOneWay ('data' )
28
+ var data;
29
+ }
30
+
22
31
23
32
// This is a baseline implementation of TreeComponent.
24
33
// It assumes the data never changes and simply throws elements on the DOM
@@ -239,6 +248,7 @@ main() {
239
248
240
249
var module = new Module ()
241
250
..type (TreeComponent )
251
+ ..type (TreeUrlComponent )
242
252
..type (NgFreeTree )
243
253
..type (NgFreeTreeScoped )
244
254
..type (NgFreeTreeClass )
Original file line number Diff line number Diff line change 14
14
</ p >
15
15
16
16
< div > Default: < input type =checkbox ng-model ="useDefault "> </ div >
17
+ < div > From URL: < input type =checkbox ng-model ="useUrl "> </ div >
17
18
< div > Baseline: < input type =checkbox ng-model ="useBaseline "> </ div >
18
19
< div > Baseline + scope: < input type =checkbox ng-model ="useBaselineScoped "> </ div >
19
20
< div > Baseline + class: < input type =checkbox ng-model ="useBaselineClass "> </ div >
20
21
21
22
22
23
< tree ng-if ="useDefault " data =initData > </ tree >
24
+ < tree-url ng-if ="useUrl " data =initData > </ tree-url >
23
25
24
26
< ng-free-tree ng-if ="useBaseline " data =initData > </ ng-free-tree >
25
27
< ng-free-tree-scoped ng-if ="useBaselineScoped " data =initData > </ ng-free-tree-scoped >
Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ class WalkingViewFactory implements ViewFactory {
118
118
@Injectable ()
119
119
class ViewCache {
120
120
// _viewFactoryCache is unbounded
121
+ // This cache contains both HTML and URL keys.
121
122
final viewFactoryCache = new LruCache <String , ViewFactory >();
122
123
final Http http;
123
124
final TemplateCache templateCache;
@@ -138,8 +139,15 @@ class ViewCache {
138
139
}
139
140
140
141
async .Future <ViewFactory > fromUrl (String url, DirectiveMap directives) {
141
- return http.get (url, cache: templateCache).then (
142
- (resp) => fromHtml (resp.responseText, directives));
142
+ ViewFactory viewFactory = viewFactoryCache.get (url);
143
+ if (viewFactory == null ) {
144
+ return http.get (url, cache: templateCache).then ((resp) {
145
+ var viewFactoryFromHttp = fromHtml (resp.responseText, directives);
146
+ viewFactoryCache.put (url, viewFactoryFromHttp);
147
+ return viewFactoryFromHttp;
148
+ });
149
+ }
150
+ return new async .Future .value (viewFactory);
143
151
}
144
152
}
145
153
Original file line number Diff line number Diff line change @@ -91,7 +91,14 @@ class PlatformViewCache implements ViewCache {
91
91
}
92
92
93
93
async .Future <ViewFactory > fromUrl (String url, DirectiveMap directives) {
94
- return http.get (url, cache: templateCache).then (
95
- (resp) => fromHtml (resp.responseText, directives));
94
+ ViewFactory viewFactory = viewFactoryCache.get (url);
95
+ if (viewFactory == null ) {
96
+ return http.get (url, cache: templateCache).then ((resp) {
97
+ var viewFactoryFromHttp = fromHtml (resp.responseText, directives);
98
+ viewFactoryCache.put (url, viewFactoryFromHttp);
99
+ return viewFactoryFromHttp;
100
+ });
101
+ }
102
+ return new async .Future .value (viewFactory);
96
103
}
97
104
}
Original file line number Diff line number Diff line change @@ -269,15 +269,9 @@ void main() {
269
269
'<style>.hello{}</style><div log="SIMPLE">Simple!</div>'
270
270
);
271
271
272
- // Since the template cache is disabled, we expect a 'simple.html' call.
273
- backend
274
- ..expectGET ('simple.html' ).respond (200 , '<div log="SIMPLE">Simple!</div>' );
275
-
276
272
var element2 = e ('<div><html-and-css>ignore</html-and-css><div>' );
277
273
compile ([element2], directives)(injector, [element2]);
278
274
279
- microLeap ();
280
- backend.flush ();
281
275
microLeap ();
282
276
283
277
expect (element2.children[0 ].shadowRoot).toHaveHtml (
You can’t perform that action at this time.
0 commit comments