Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 36d93d8

Browse files
committed
fix(ViewCache): Use an unbounded cache in the ViewCache.
ViewCache was broken by the LruCache change in 3e60863. Between that change and this one, it was not caching any views. Also, add a test.
1 parent 4dfd99b commit 36d93d8

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Diff for: lib/core_dom/view_factory.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class WalkingViewFactory implements ViewFactory {
118118
@Injectable()
119119
class ViewCache {
120120
// _viewFactoryCache is unbounded
121-
final _viewFactoryCache = new LruCache<String, ViewFactory>(capacity: 0);
121+
final _viewFactoryCache = new LruCache<String, ViewFactory>();
122122
final Http http;
123123
final TemplateCache templateCache;
124124
final Compiler compiler;

Diff for: test/core_dom/view_cache_spec.dart

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
library angular.dom.view_cache_spec;
2+
3+
import '../_specs.dart';
4+
5+
main() {
6+
describe('ViewCache', () {
7+
var HTML = '<div>html</div>';
8+
var mockCompiler;
9+
beforeEachModule((Module module) {
10+
var httpBackend = new MockHttpBackend();
11+
12+
module
13+
..bind(HttpBackend, toValue: httpBackend)
14+
..bind(MockHttpBackend, toValue: httpBackend);
15+
});
16+
17+
it('should cache the ViewFactory', async((
18+
ViewCache cache, MockHttpBackend backend, DirectiveMap directives) {
19+
var firstFactory = cache.fromHtml(HTML, directives);
20+
21+
expect(cache.fromHtml(HTML, directives)).toBe(firstFactory);
22+
23+
// Also for fromUrl
24+
backend.whenGET('template.url').respond(200, HTML);
25+
26+
var httpFactory;
27+
cache.fromUrl('template.url', directives).then((f) => httpFactory = f);
28+
29+
microLeap();
30+
backend.flush();
31+
microLeap();
32+
33+
expect(httpFactory).toBe(firstFactory);
34+
}));
35+
});
36+
}

0 commit comments

Comments
 (0)