fix(viewFactory): allow empty view cache

This commit is contained in:
Tobias Bosch 2015-04-17 14:37:57 -07:00
parent abda569b55
commit 02997f473a
5 changed files with 9 additions and 17 deletions

View File

@ -26,12 +26,8 @@ export class ViewFactory {
getView(protoView:viewModule.AppProtoView):viewModule.AppView { getView(protoView:viewModule.AppProtoView):viewModule.AppView {
var pooledViews = MapWrapper.get(this._pooledViewsPerProtoView, protoView); var pooledViews = MapWrapper.get(this._pooledViewsPerProtoView, protoView);
if (isPresent(pooledViews)) { if (isPresent(pooledViews) && pooledViews.length > 0) {
var result = ListWrapper.removeLast(pooledViews); return ListWrapper.removeLast(pooledViews);
if (pooledViews.length === 0) {
MapWrapper.delete(this._pooledViewsPerProtoView, protoView);
}
return result;
} }
return this._createView(protoView); return this._createView(protoView);
} }

View File

@ -36,12 +36,8 @@ export class ViewFactory {
getView(protoView:pvModule.RenderProtoView):viewModule.RenderView { getView(protoView:pvModule.RenderProtoView):viewModule.RenderView {
var pooledViews = MapWrapper.get(this._pooledViewsPerProtoView, protoView); var pooledViews = MapWrapper.get(this._pooledViewsPerProtoView, protoView);
if (isPresent(pooledViews)) { if (isPresent(pooledViews) && pooledViews.length > 0) {
var result = ListWrapper.removeLast(pooledViews); return ListWrapper.removeLast(pooledViews);
if (pooledViews.length === 0) {
MapWrapper.delete(this._pooledViewsPerProtoView, protoView);
}
return result;
} }
return this._createView(protoView, null); return this._createView(protoView, null);
} }

View File

@ -66,10 +66,10 @@ export function main() {
return binder; return binder;
} }
it('should create views', () => { it('should create views without cache', () => {
var pv = createProtoView(); var pv = createProtoView();
var vf = createViewFactory({ var vf = createViewFactory({
capacity: 1 capacity: 0
}); });
expect(vf.getView(pv) instanceof AppView).toBe(true); expect(vf.getView(pv) instanceof AppView).toBe(true);
}); });

View File

@ -38,7 +38,7 @@ export class IntegrationTestbed {
var compiler = new Compiler(new DefaultStepFactory(parser, shadowDomStrategy), new FakeTemplateLoader(urlResolver, urlData)); var compiler = new Compiler(new DefaultStepFactory(parser, shadowDomStrategy), new FakeTemplateLoader(urlResolver, urlData));
if (isBlank(viewCacheCapacity)) { if (isBlank(viewCacheCapacity)) {
viewCacheCapacity = 1; viewCacheCapacity = 0;
} }
if (isBlank(urlData)) { if (isBlank(urlData)) {
urlData = MapWrapper.create(); urlData = MapWrapper.create();

View File

@ -61,10 +61,10 @@ export function main() {
shadowDomStrategy = new SpyShadowDomStrategy(); shadowDomStrategy = new SpyShadowDomStrategy();
}); });
it('should create views', () => { it('should create views without cache', () => {
var pv = createProtoView(); var pv = createProtoView();
var vf = createViewFactory({ var vf = createViewFactory({
capacity: 1 capacity: 0
}); });
expect(vf.getView(pv) instanceof RenderView).toBe(true); expect(vf.getView(pv) instanceof RenderView).toBe(true);
}); });