refactor(benchmarks): make ftl benchmarks use their own version of `checkBinding`

This commit is contained in:
Tobias Bosch 2016-12-29 15:00:50 -08:00 committed by Igor Minar
parent 50e5cb15dd
commit 8ed92d75b0
7 changed files with 47 additions and 23 deletions

View File

@ -7,6 +7,9 @@
*/
import {ComponentFactory, ComponentRef, ElementRef, Injector, TemplateRef, ViewContainerRef, ViewRef} from '@angular/core';
import {devModeEqual, looseIdentical} from '@angular/core/src/change_detection/change_detection_util';
import {ExpressionChangedAfterItHasBeenCheckedError} from '@angular/core/src/linker/errors';
export function unimplemented(): any {
throw new Error('unimplemented');
@ -205,3 +208,14 @@ export function createAnchorAndAppend(parent: any) {
parent.appendChild(txt);
return txt;
}
export function checkBinding(throwOnChange: boolean, oldValue: any, newValue: any): boolean {
if (throwOnChange) {
if (!devModeEqual(oldValue, newValue)) {
throw new ExpressionChangedAfterItHasBeenCheckedError(oldValue, newValue, false);
}
return false;
} else {
return !looseIdentical(oldValue, newValue);
}
}

View File

@ -2,17 +2,17 @@ import {NgIf} from '@angular/common';
import {TemplateRef, ViewContainerRef} from '@angular/core';
import * as import7 from '@angular/core/src/change_detection/change_detection';
import * as import4 from '@angular/core/src/linker/view_utils';
import {checkBinding} from './ftl_util';
export class NgIfWrapper {
directive: NgIf;
_expr_0: any;
constructor(viewContainerRef: ViewContainerRef, templateRef: TemplateRef<any>) {
this.directive = new NgIf(viewContainerRef, templateRef);
this._expr_0 = import7.UNINITIALIZED;
}
updateNgIf(throwOnChange: boolean, currVal: any) {
if (import4.checkBinding(throwOnChange, this._expr_0, currVal)) {
if (checkBinding(throwOnChange, this._expr_0, currVal)) {
this.directive.ngIf = currVal;
this._expr_0 = currVal;
}

View File

@ -18,7 +18,7 @@ import * as import8 from '@angular/core/src/metadata/view';
import * as import0 from '@angular/core/src/render/api';
import * as import12 from '@angular/core/src/security';
import {FtlEmbeddedView, FtlTemplateRef, FtlView, FtlViewContainerRef, createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
import {FtlEmbeddedView, FtlTemplateRef, FtlView, FtlViewContainerRef, checkBinding, createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
import {NgIfWrapper} from './ng_if.ngfactory';
import * as import3 from './tree';
@ -50,9 +50,8 @@ export class _View_TreeComponent0 implements FtlView<import3.TreeComponent> {
this._TemplateRef_3_5 = new FtlTemplateRef(3, this);
this._vc_3 = new FtlViewContainerRef(this._anchor_3);
this._NgIf_3_6 = new NgIfWrapper(this._vc_3, this._TemplateRef_3_5);
this._expr_0 = import7.UNINITIALIZED;
this._expr_1 = import7.UNINITIALIZED;
this._expr_2 = import7.UNINITIALIZED;
this._expr_0 = undefined;
this._expr_1 = undefined;
}
detectChangesInternal(throwOnChange: boolean): void {
this._NgIf_2_6.updateNgIf(throwOnChange, (this.context.data.right != (null as any)));
@ -60,12 +59,12 @@ export class _View_TreeComponent0 implements FtlView<import3.TreeComponent> {
this._vc_2.detectChangesInternal(throwOnChange);
this._vc_3.detectChangesInternal(throwOnChange);
const currVal_0: any = ((this.context.data.depth % 2) ? '' : 'grey');
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
this._el_0.style.backgroundColor = currVal_0;
this._expr_0 = currVal_0;
}
const currVal_1: any = import4.inlineInterpolate(1, ' ', this.context.data.value, ' ');
if (import4.checkBinding(throwOnChange, this._expr_1, currVal_1)) {
if (checkBinding(throwOnChange, this._expr_1, currVal_1)) {
this._text_1.nodeValue = currVal_1;
this._expr_1 = currVal_1;
}
@ -75,7 +74,7 @@ export class _View_TreeComponent0 implements FtlView<import3.TreeComponent> {
this._vc_3.destroyInternal();
}
updateData(throwOnChange: boolean, currVal: any) {
if (import4.checkBinding(throwOnChange, this._expr_2, currVal)) {
if (checkBinding(throwOnChange, this._expr_2, currVal)) {
this.context.data = currVal;
this._expr_2 = currVal;
}

View File

@ -5,6 +5,8 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {devModeEqual, looseIdentical} from '@angular/core/src/change_detection/change_detection_util';
import {ExpressionChangedAfterItHasBeenCheckedError} from '@angular/core/src/linker/errors';
export function createElementAndAppend(parent: any, name: string) {
const el = document.createElement(name);
@ -23,3 +25,14 @@ export function createAnchorAndAppend(parent: any) {
parent.appendChild(txt);
return txt;
}
export function checkBinding(throwOnChange: boolean, oldValue: any, newValue: any): boolean {
if (throwOnChange) {
if (!devModeEqual(oldValue, newValue)) {
throw new ExpressionChangedAfterItHasBeenCheckedError(oldValue, newValue, false);
}
return false;
} else {
return !looseIdentical(oldValue, newValue);
}
}

View File

@ -16,7 +16,7 @@ import * as import8 from '@angular/core/src/metadata/view';
import * as import0 from '@angular/core/src/render/api';
import * as import12 from '@angular/core/src/security';
import {createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
import {checkBinding, createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
import * as import3 from './tree';
import * as import11 from './tree_leaf.ngfactory';
@ -42,16 +42,15 @@ export class View_TreeTreeComponent {
this._el_3 = createElementAndAppend(parentRenderNode, 'tree');
this._TreeComponent20_3_4View = depth > 0 ? new View_TreeTreeComponent(depth - 1, this._el_3) :
new import11.View_TreeLeafComponent(this._el_3);
this._expr_0 = import7.UNINITIALIZED;
this._expr_1 = import7.UNINITIALIZED;
this._expr_2 = import7.UNINITIALIZED;
this._expr_1 = undefined;
this._expr_2 = undefined;
}
destroyInternal() {
this._TreeComponent20_2_4View.destroyInternal();
this._TreeComponent20_3_4View.destroyInternal();
}
updateData(currVal_2: any) {
if (import4.checkBinding(false, this._expr_2, currVal_2)) {
if (checkBinding(false, this._expr_2, currVal_2)) {
this.context.data = currVal_2;
this._expr_2 = currVal_2;
}
@ -61,12 +60,12 @@ export class View_TreeTreeComponent {
this._TreeComponent20_3_4View.updateData(this.context.data.left);
const currVal_0: any = ((this.context.data.depth % 2) ? '' : 'grey');
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
this._el_0.style.backgroundColor = currVal_0;
this._expr_0 = currVal_0;
}
const currVal_1: any = import4.inlineInterpolate(1, ' ', this.context.data.value, ' ');
if (import4.checkBinding(throwOnChange, this._expr_1, currVal_1)) {
if (checkBinding(throwOnChange, this._expr_1, currVal_1)) {
this._text_1.nodeValue = currVal_1;
this._expr_1 = currVal_1;
}

View File

@ -16,6 +16,7 @@ import * as import8 from '@angular/core/src/metadata/view';
import * as import0 from '@angular/core/src/render/api';
import * as import10 from '@angular/core/src/security';
import {checkBinding} from './ftl_util';
import * as import3 from './tree';
export class View_TreeLeafComponent {
@ -31,11 +32,9 @@ export class View_TreeLeafComponent {
parentRenderNode.appendChild(this._el_0);
this._text_1 = document.createTextNode('');
this._el_0.appendChild(this._text_1);
this._expr_0 = import7.UNINITIALIZED;
this._expr_1 = import7.UNINITIALIZED;
}
updateData(currVal_2: any) {
if (import4.checkBinding(false, this._expr_2, currVal_2)) {
if (checkBinding(false, this._expr_2, currVal_2)) {
this.context.data = currVal_2;
this._expr_2 = currVal_2;
}
@ -43,12 +42,12 @@ export class View_TreeLeafComponent {
destroyInternal() {}
detectChangesInternal(throwOnChange: boolean): void {
const currVal_0: any = ((this.context.data.depth % 2) ? '' : 'grey');
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
this._el_0.style.backgroundColor = currVal_0;
this._expr_0 = currVal_0;
}
const currVal_1: any = import4.inlineInterpolate(1, ' ', this.context.data.value, ' ');
if (import4.checkBinding(throwOnChange, this._expr_1, currVal_1)) {
if (checkBinding(throwOnChange, this._expr_1, currVal_1)) {
this._text_1.nodeValue = currVal_1;
this._expr_1 = currVal_1;
}

View File

@ -18,6 +18,7 @@ import * as import0 from '@angular/core/src/render/api';
import {maxDepth} from '../util';
import {checkBinding} from './ftl_util';
import * as import3 from './tree';
import * as import12 from './tree';
import * as import13 from './tree_branch.ngfactory';
@ -86,7 +87,6 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
this._appEl_0 = new import2.ViewContainer(0, (null as any), this, this._anchor_0);
this._TemplateRef_0_5 = new import11.TemplateRef_(this, 0, this._anchor_0);
this._NgIf_0_6 = new import10.NgIf(this._appEl_0.vcRef, this._TemplateRef_0_5);
this._expr_0 = import7.UNINITIALIZED;
this.init([], [this._anchor_0], []);
return (null as any);
}
@ -108,7 +108,7 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
}
detectChangesInternal(throwOnChange: boolean): void {
const currVal_0: any = (this.context.data.left != (null as any));
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
this._NgIf_0_6.ngIf = currVal_0;
this._expr_0 = currVal_0;
}