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

Commit

Permalink
fix(ViewCache): Use an unbounded cache in the ViewCache.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbdeboer committed May 10, 2014
1 parent 4dfd99b commit 36d93d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core_dom/view_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class WalkingViewFactory implements ViewFactory {
@Injectable()
class ViewCache {
// _viewFactoryCache is unbounded
final _viewFactoryCache = new LruCache<String, ViewFactory>(capacity: 0);
final _viewFactoryCache = new LruCache<String, ViewFactory>();
final Http http;
final TemplateCache templateCache;
final Compiler compiler;
Expand Down
36 changes: 36 additions & 0 deletions test/core_dom/view_cache_spec.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
library angular.dom.view_cache_spec;

import '../_specs.dart';

main() {
describe('ViewCache', () {
var HTML = '<div>html</div>';
var mockCompiler;
beforeEachModule((Module module) {
var httpBackend = new MockHttpBackend();

module
..bind(HttpBackend, toValue: httpBackend)
..bind(MockHttpBackend, toValue: httpBackend);
});

it('should cache the ViewFactory', async((
ViewCache cache, MockHttpBackend backend, DirectiveMap directives) {
var firstFactory = cache.fromHtml(HTML, directives);

expect(cache.fromHtml(HTML, directives)).toBe(firstFactory);

// Also for fromUrl
backend.whenGET('template.url').respond(200, HTML);

var httpFactory;
cache.fromUrl('template.url', directives).then((f) => httpFactory = f);

microLeap();
backend.flush();
microLeap();

expect(httpFactory).toBe(firstFactory);
}));
});
}

0 comments on commit 36d93d8

Please sign in to comment.