feat(core): add `begin` and `end` renderer methods to track change detection
This commit is contained in:
parent
8931e71c5c
commit
7f9c589ba3
|
@ -127,6 +127,8 @@ export interface RendererType2 {
|
|||
*/
|
||||
export abstract class RendererFactory2 {
|
||||
abstract createRenderer(hostElement: any, type: RendererType2|null): Renderer2;
|
||||
abstract begin?(): void;
|
||||
abstract end?(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -239,7 +239,16 @@ export class ViewRef_ implements EmbeddedViewRef<any>, InternalViewRef {
|
|||
|
||||
markForCheck(): void { markParentViewsForCheck(this._view); }
|
||||
detach(): void { this._view.state &= ~ViewState.Attached; }
|
||||
detectChanges(): void { Services.checkAndUpdateView(this._view); }
|
||||
detectChanges(): void {
|
||||
const fs = this._view.root.rendererFactory;
|
||||
if (fs.begin) {
|
||||
fs.begin();
|
||||
}
|
||||
Services.checkAndUpdateView(this._view);
|
||||
if (fs.end) {
|
||||
fs.end();
|
||||
}
|
||||
}
|
||||
checkNoChanges(): void { Services.checkNoChangesView(this._view); }
|
||||
|
||||
reattach(): void { this._view.state |= ViewState.Attached; }
|
||||
|
|
|
@ -456,6 +456,17 @@ class DebugRendererFactory2 implements RendererFactory2 {
|
|||
createRenderer(element: any, renderData: RendererType2|null): Renderer2 {
|
||||
return new DebugRenderer2(this.delegate.createRenderer(element, renderData));
|
||||
}
|
||||
|
||||
begin() {
|
||||
if (this.delegate.begin) {
|
||||
this.delegate.begin();
|
||||
}
|
||||
}
|
||||
end() {
|
||||
if (this.delegate.end) {
|
||||
this.delegate.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -666,6 +666,22 @@ export function main() {
|
|||
|
||||
});
|
||||
|
||||
describe('RendererFactory', () => {
|
||||
it('should call the begin and end methods on the renderer factory when change detection is called',
|
||||
fakeAsync(() => {
|
||||
const ctx = createCompFixture('<div testDirective [a]="42"></div>');
|
||||
const rf = TestBed.get(RendererFactory2);
|
||||
spyOn(rf, 'begin');
|
||||
spyOn(rf, 'end');
|
||||
expect(rf.begin).not.toHaveBeenCalled();
|
||||
expect(rf.end).not.toHaveBeenCalled();
|
||||
|
||||
ctx.detectChanges(false);
|
||||
expect(rf.begin).toHaveBeenCalled();
|
||||
expect(rf.end).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('change notification', () => {
|
||||
describe('updating directives', () => {
|
||||
it('should happen without invoking the renderer', fakeAsync(() => {
|
||||
|
|
|
@ -25,6 +25,17 @@ export class AnimationRendererFactory implements RendererFactory2 {
|
|||
trigger => this._engine.registerTrigger(trigger, namespaceify(namespaceId, trigger.name)));
|
||||
return new AnimationRenderer(delegate, this._engine, this._zone, namespaceId);
|
||||
}
|
||||
|
||||
begin() {
|
||||
if (this.delegate.begin) {
|
||||
this.delegate.begin();
|
||||
}
|
||||
}
|
||||
end() {
|
||||
if (this.delegate.end) {
|
||||
this.delegate.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class AnimationRenderer implements Renderer2 {
|
||||
|
|
|
@ -94,6 +94,9 @@ export class DomRendererFactory2 implements RendererFactory2 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
begin() {}
|
||||
end() {}
|
||||
}
|
||||
|
||||
class DefaultDomRenderer2 implements Renderer2 {
|
||||
|
|
|
@ -52,6 +52,9 @@ export class ServerRendererFactory2 implements RendererFactory2 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
begin() {}
|
||||
end() {}
|
||||
}
|
||||
|
||||
class DefaultServerRenderer2 implements Renderer2 {
|
||||
|
|
|
@ -81,6 +81,9 @@ export class WebWorkerRendererFactory2 implements RendererFactory2 {
|
|||
return renderer;
|
||||
}
|
||||
|
||||
begin() {}
|
||||
end() {}
|
||||
|
||||
callUI(fnName: string, fnArgs: FnArg[]) {
|
||||
const args = new UiArguments(fnName, fnArgs);
|
||||
this._messageBroker.runOnService(args, null);
|
||||
|
|
|
@ -846,7 +846,9 @@ export declare abstract class Renderer2 {
|
|||
|
||||
/** @experimental */
|
||||
export declare abstract class RendererFactory2 {
|
||||
abstract begin?(): void;
|
||||
abstract createRenderer(hostElement: any, type: RendererType2 | null): Renderer2;
|
||||
abstract end?(): void;
|
||||
}
|
||||
|
||||
/** @experimental */
|
||||
|
|
Loading…
Reference in New Issue