Skip to content

Commit

Permalink
refactor(benchmarks): make ftl benchmarks use their own version of `c…
Browse files Browse the repository at this point in the history
…heckBinding`
  • Loading branch information
tbosch authored and IgorMinar committed Jan 3, 2017
1 parent 50e5cb1 commit 8ed92d7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 23 deletions.
14 changes: 14 additions & 0 deletions modules/benchmarks/src/tree/ng2_ftl/ftl_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions modules/benchmarks/src/tree/ng2_ftl/ng_if.ngfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 6 additions & 7 deletions modules/benchmarks/src/tree/ng2_ftl/tree.ngfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -50,22 +50,21 @@ 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)));
this._NgIf_3_6.updateNgIf(throwOnChange, (this.context.data.left != (null as any)));
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;
}
Expand All @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions modules/benchmarks/src/tree/ng2_static_ftl/ftl_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,24 +32,22 @@ 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;
}
}
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 8ed92d7

Please sign in to comment.