Skip to content

Commit 8ed92d7

Browse files
tboschIgorMinar
authored andcommitted
refactor(benchmarks): make ftl benchmarks use their own version of checkBinding
1 parent 50e5cb1 commit 8ed92d7

File tree

7 files changed

+47
-23
lines changed

7 files changed

+47
-23
lines changed

modules/benchmarks/src/tree/ng2_ftl/ftl_util.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88

99
import {ComponentFactory, ComponentRef, ElementRef, Injector, TemplateRef, ViewContainerRef, ViewRef} from '@angular/core';
10+
import {devModeEqual, looseIdentical} from '@angular/core/src/change_detection/change_detection_util';
11+
import {ExpressionChangedAfterItHasBeenCheckedError} from '@angular/core/src/linker/errors';
12+
1013

1114
export function unimplemented(): any {
1215
throw new Error('unimplemented');
@@ -205,3 +208,14 @@ export function createAnchorAndAppend(parent: any) {
205208
parent.appendChild(txt);
206209
return txt;
207210
}
211+
212+
export function checkBinding(throwOnChange: boolean, oldValue: any, newValue: any): boolean {
213+
if (throwOnChange) {
214+
if (!devModeEqual(oldValue, newValue)) {
215+
throw new ExpressionChangedAfterItHasBeenCheckedError(oldValue, newValue, false);
216+
}
217+
return false;
218+
} else {
219+
return !looseIdentical(oldValue, newValue);
220+
}
221+
}

modules/benchmarks/src/tree/ng2_ftl/ng_if.ngfactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import {NgIf} from '@angular/common';
22
import {TemplateRef, ViewContainerRef} from '@angular/core';
33
import * as import7 from '@angular/core/src/change_detection/change_detection';
44
import * as import4 from '@angular/core/src/linker/view_utils';
5+
import {checkBinding} from './ftl_util';
56

67
export class NgIfWrapper {
78
directive: NgIf;
89
_expr_0: any;
910
constructor(viewContainerRef: ViewContainerRef, templateRef: TemplateRef<any>) {
1011
this.directive = new NgIf(viewContainerRef, templateRef);
11-
this._expr_0 = import7.UNINITIALIZED;
1212
}
1313

1414
updateNgIf(throwOnChange: boolean, currVal: any) {
15-
if (import4.checkBinding(throwOnChange, this._expr_0, currVal)) {
15+
if (checkBinding(throwOnChange, this._expr_0, currVal)) {
1616
this.directive.ngIf = currVal;
1717
this._expr_0 = currVal;
1818
}

modules/benchmarks/src/tree/ng2_ftl/tree.ngfactory.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as import8 from '@angular/core/src/metadata/view';
1818
import * as import0 from '@angular/core/src/render/api';
1919
import * as import12 from '@angular/core/src/security';
2020

21-
import {FtlEmbeddedView, FtlTemplateRef, FtlView, FtlViewContainerRef, createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
21+
import {FtlEmbeddedView, FtlTemplateRef, FtlView, FtlViewContainerRef, checkBinding, createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
2222
import {NgIfWrapper} from './ng_if.ngfactory';
2323
import * as import3 from './tree';
2424

@@ -50,22 +50,21 @@ export class _View_TreeComponent0 implements FtlView<import3.TreeComponent> {
5050
this._TemplateRef_3_5 = new FtlTemplateRef(3, this);
5151
this._vc_3 = new FtlViewContainerRef(this._anchor_3);
5252
this._NgIf_3_6 = new NgIfWrapper(this._vc_3, this._TemplateRef_3_5);
53-
this._expr_0 = import7.UNINITIALIZED;
54-
this._expr_1 = import7.UNINITIALIZED;
55-
this._expr_2 = import7.UNINITIALIZED;
53+
this._expr_0 = undefined;
54+
this._expr_1 = undefined;
5655
}
5756
detectChangesInternal(throwOnChange: boolean): void {
5857
this._NgIf_2_6.updateNgIf(throwOnChange, (this.context.data.right != (null as any)));
5958
this._NgIf_3_6.updateNgIf(throwOnChange, (this.context.data.left != (null as any)));
6059
this._vc_2.detectChangesInternal(throwOnChange);
6160
this._vc_3.detectChangesInternal(throwOnChange);
6261
const currVal_0: any = ((this.context.data.depth % 2) ? '' : 'grey');
63-
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
62+
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
6463
this._el_0.style.backgroundColor = currVal_0;
6564
this._expr_0 = currVal_0;
6665
}
6766
const currVal_1: any = import4.inlineInterpolate(1, ' ', this.context.data.value, ' ');
68-
if (import4.checkBinding(throwOnChange, this._expr_1, currVal_1)) {
67+
if (checkBinding(throwOnChange, this._expr_1, currVal_1)) {
6968
this._text_1.nodeValue = currVal_1;
7069
this._expr_1 = currVal_1;
7170
}
@@ -75,7 +74,7 @@ export class _View_TreeComponent0 implements FtlView<import3.TreeComponent> {
7574
this._vc_3.destroyInternal();
7675
}
7776
updateData(throwOnChange: boolean, currVal: any) {
78-
if (import4.checkBinding(throwOnChange, this._expr_2, currVal)) {
77+
if (checkBinding(throwOnChange, this._expr_2, currVal)) {
7978
this.context.data = currVal;
8079
this._expr_2 = currVal;
8180
}

modules/benchmarks/src/tree/ng2_static_ftl/ftl_util.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import {devModeEqual, looseIdentical} from '@angular/core/src/change_detection/change_detection_util';
9+
import {ExpressionChangedAfterItHasBeenCheckedError} from '@angular/core/src/linker/errors';
810

911
export function createElementAndAppend(parent: any, name: string) {
1012
const el = document.createElement(name);
@@ -23,3 +25,14 @@ export function createAnchorAndAppend(parent: any) {
2325
parent.appendChild(txt);
2426
return txt;
2527
}
28+
29+
export function checkBinding(throwOnChange: boolean, oldValue: any, newValue: any): boolean {
30+
if (throwOnChange) {
31+
if (!devModeEqual(oldValue, newValue)) {
32+
throw new ExpressionChangedAfterItHasBeenCheckedError(oldValue, newValue, false);
33+
}
34+
return false;
35+
} else {
36+
return !looseIdentical(oldValue, newValue);
37+
}
38+
}

modules/benchmarks/src/tree/ng2_static_ftl/tree_branch.ngfactory.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as import8 from '@angular/core/src/metadata/view';
1616
import * as import0 from '@angular/core/src/render/api';
1717
import * as import12 from '@angular/core/src/security';
1818

19-
import {createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
19+
import {checkBinding, createAnchorAndAppend, createElementAndAppend, createTextAndAppend} from './ftl_util';
2020
import * as import3 from './tree';
2121
import * as import11 from './tree_leaf.ngfactory';
2222

@@ -42,16 +42,15 @@ export class View_TreeTreeComponent {
4242
this._el_3 = createElementAndAppend(parentRenderNode, 'tree');
4343
this._TreeComponent20_3_4View = depth > 0 ? new View_TreeTreeComponent(depth - 1, this._el_3) :
4444
new import11.View_TreeLeafComponent(this._el_3);
45-
this._expr_0 = import7.UNINITIALIZED;
46-
this._expr_1 = import7.UNINITIALIZED;
47-
this._expr_2 = import7.UNINITIALIZED;
45+
this._expr_1 = undefined;
46+
this._expr_2 = undefined;
4847
}
4948
destroyInternal() {
5049
this._TreeComponent20_2_4View.destroyInternal();
5150
this._TreeComponent20_3_4View.destroyInternal();
5251
}
5352
updateData(currVal_2: any) {
54-
if (import4.checkBinding(false, this._expr_2, currVal_2)) {
53+
if (checkBinding(false, this._expr_2, currVal_2)) {
5554
this.context.data = currVal_2;
5655
this._expr_2 = currVal_2;
5756
}
@@ -61,12 +60,12 @@ export class View_TreeTreeComponent {
6160
this._TreeComponent20_3_4View.updateData(this.context.data.left);
6261

6362
const currVal_0: any = ((this.context.data.depth % 2) ? '' : 'grey');
64-
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
63+
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
6564
this._el_0.style.backgroundColor = currVal_0;
6665
this._expr_0 = currVal_0;
6766
}
6867
const currVal_1: any = import4.inlineInterpolate(1, ' ', this.context.data.value, ' ');
69-
if (import4.checkBinding(throwOnChange, this._expr_1, currVal_1)) {
68+
if (checkBinding(throwOnChange, this._expr_1, currVal_1)) {
7069
this._text_1.nodeValue = currVal_1;
7170
this._expr_1 = currVal_1;
7271
}

modules/benchmarks/src/tree/ng2_static_ftl/tree_leaf.ngfactory.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as import8 from '@angular/core/src/metadata/view';
1616
import * as import0 from '@angular/core/src/render/api';
1717
import * as import10 from '@angular/core/src/security';
1818

19+
import {checkBinding} from './ftl_util';
1920
import * as import3 from './tree';
2021

2122
export class View_TreeLeafComponent {
@@ -31,24 +32,22 @@ export class View_TreeLeafComponent {
3132
parentRenderNode.appendChild(this._el_0);
3233
this._text_1 = document.createTextNode('');
3334
this._el_0.appendChild(this._text_1);
34-
this._expr_0 = import7.UNINITIALIZED;
35-
this._expr_1 = import7.UNINITIALIZED;
3635
}
3736
updateData(currVal_2: any) {
38-
if (import4.checkBinding(false, this._expr_2, currVal_2)) {
37+
if (checkBinding(false, this._expr_2, currVal_2)) {
3938
this.context.data = currVal_2;
4039
this._expr_2 = currVal_2;
4140
}
4241
}
4342
destroyInternal() {}
4443
detectChangesInternal(throwOnChange: boolean): void {
4544
const currVal_0: any = ((this.context.data.depth % 2) ? '' : 'grey');
46-
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
45+
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
4746
this._el_0.style.backgroundColor = currVal_0;
4847
this._expr_0 = currVal_0;
4948
}
5049
const currVal_1: any = import4.inlineInterpolate(1, ' ', this.context.data.value, ' ');
51-
if (import4.checkBinding(throwOnChange, this._expr_1, currVal_1)) {
50+
if (checkBinding(throwOnChange, this._expr_1, currVal_1)) {
5251
this._text_1.nodeValue = currVal_1;
5352
this._expr_1 = currVal_1;
5453
}

modules/benchmarks/src/tree/ng2_static_ftl/tree_root.ngfactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as import0 from '@angular/core/src/render/api';
1818

1919
import {maxDepth} from '../util';
2020

21+
import {checkBinding} from './ftl_util';
2122
import * as import3 from './tree';
2223
import * as import12 from './tree';
2324
import * as import13 from './tree_branch.ngfactory';
@@ -86,7 +87,6 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
8687
this._appEl_0 = new import2.ViewContainer(0, (null as any), this, this._anchor_0);
8788
this._TemplateRef_0_5 = new import11.TemplateRef_(this, 0, this._anchor_0);
8889
this._NgIf_0_6 = new import10.NgIf(this._appEl_0.vcRef, this._TemplateRef_0_5);
89-
this._expr_0 = import7.UNINITIALIZED;
9090
this.init([], [this._anchor_0], []);
9191
return (null as any);
9292
}
@@ -108,7 +108,7 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
108108
}
109109
detectChangesInternal(throwOnChange: boolean): void {
110110
const currVal_0: any = (this.context.data.left != (null as any));
111-
if (import4.checkBinding(throwOnChange, this._expr_0, currVal_0)) {
111+
if (checkBinding(throwOnChange, this._expr_0, currVal_0)) {
112112
this._NgIf_0_6.ngIf = currVal_0;
113113
this._expr_0 = currVal_0;
114114
}

0 commit comments

Comments
 (0)