feat(view_pool): adds a view pool of dehydrated views per protoview.
This commit is contained in:
46
modules/angular2/test/core/compiler/view_pool_spec.js
vendored
Normal file
46
modules/angular2/test/core/compiler/view_pool_spec.js
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
import {describe, xit, it, expect, beforeEach, ddescribe, iit, el} from 'angular2/test_lib';
|
||||
|
||||
import {View} from 'angular2/src/core/compiler/view';
|
||||
import {ViewPool} from 'angular2/src/core/compiler/view_pool';
|
||||
import {proxy, IMPLEMENTS} from 'angular2/src/facade/lang';
|
||||
|
||||
@proxy
|
||||
@IMPLEMENTS(View)
|
||||
class FakeView {
|
||||
noSuchMethod(i) {
|
||||
super.noSuchMethod(i);
|
||||
}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('ViewPool', () => {
|
||||
var viewPool, capacity = 3;
|
||||
beforeEach(() => {
|
||||
viewPool = new ViewPool(capacity);
|
||||
})
|
||||
|
||||
it('should return null when there are no views', () => {
|
||||
expect(viewPool.pop()).toBeNull();
|
||||
expect(viewPool.length()).toBe(0);
|
||||
})
|
||||
|
||||
it('should support storing and retrieving a view', () => {
|
||||
var view = new FakeView();
|
||||
viewPool.push(view);
|
||||
expect(viewPool.length()).toBe(1);
|
||||
|
||||
expect(viewPool.pop()).toBe(view);
|
||||
expect(viewPool.length()).toBe(0);
|
||||
})
|
||||
|
||||
it('should not store more views that its capacity', () => {
|
||||
for (var i = 0; i < capacity * 2; i++) viewPool.push(new FakeView());
|
||||
expect(viewPool.length()).toBe(capacity);
|
||||
|
||||
for (var i = 0; i < capacity; i++) {
|
||||
expect(viewPool.pop()).not.toBe(null);
|
||||
}
|
||||
expect(viewPool.pop()).toBeNull();
|
||||
})
|
||||
})
|
||||
}
|
15
modules/angular2/test/core/compiler/view_spec.js
vendored
15
modules/angular2/test/core/compiler/view_spec.js
vendored
@ -31,6 +31,13 @@ class FakeViewPort {
|
||||
}
|
||||
}
|
||||
|
||||
@proxy
|
||||
@IMPLEMENTS(View)
|
||||
class FakeView {
|
||||
noSuchMethod(i) {
|
||||
super.noSuchMethod(i);
|
||||
}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('view', function() {
|
||||
@ -68,6 +75,14 @@ export function main() {
|
||||
view.dehydrate();
|
||||
expect(view.hydrated()).toBe(false);
|
||||
});
|
||||
|
||||
it('should use the view pool to reuse views', () => {
|
||||
var pv = new ProtoView(el('<div id="1"></div>'), new DynamicProtoChangeDetector(), null);
|
||||
var fakeView = new FakeView();
|
||||
pv.returnToPool(fakeView);
|
||||
|
||||
expect(pv.instantiate(null)).toBe(fakeView);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with locals', function() {
|
||||
|
Reference in New Issue
Block a user