Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active December 14, 2016 09:08
Show Gist options
  • Save robwormald/240b90ecf21af655ecf28a22a35f5627 to your computer and use it in GitHub Desktop.
Save robwormald/240b90ecf21af655ecf28a22a35f5627 to your computer and use it in GitHub Desktop.
<p>hello {{name}}</p>
@Component({
selector: 'hello-component',
templateUrl: 'hello-component.html'
})
export class HelloComponent {
name: string;
constructor(){
this.name = 'World';
setTimeout(() => this.name = 'World!!!', 1000);
}
}
export class View_HelloComponent0 extends AppView {
constructor(viewUtils, parentView, parentIndex, parentElement) {
super(View_HelloComponent0, renderType_HelloComponent, ViewType.COMPONENT, viewUtils, parentView, parentIndex, parentElement, ChangeDetectorStatus.CheckAlways);
this._expr_2 = UNINITIALIZED;
}
createInternal(rootSelector) {
const parentRenderNode = this.renderer.createViewRoot(this.parentElement);
this._el_0 = createRenderElement(this.renderer, parentRenderNode, 'p', EMPTY_INLINE_ARRAY, null);
this._text_1 = this.renderer.createText(this._el_0, '', null);
this.init(null, (this.renderer.directRenderer ? null : [
this._el_0,
this._text_1
]), null);
return null;
}
detectChangesInternal(throwOnChange) {
const currVal_2 = inlineInterpolate(1, 'hello ', this.context.name, '');
if (checkBinding(throwOnChange, this._expr_2, currVal_2)) {
this.renderer.setText(this._text_1, currVal_2);
this._expr_2 = currVal_2;
}
}
}
@slmyers
Copy link

slmyers commented Dec 13, 2016

I've read a few articles/posts about how Angular2 change detection is quick because of monomorphic change detection functions. Is an example of this present here? I think it's the checkBinding(...) call but I would like to be sure before (or if) I explain to others.

@calebboyd
Copy link

calebboyd commented Dec 14, 2016

@slmyers Thats exactly what is happening here, and why we don't see .name or a reflective property access (this[prop]) anywhere in the compiled code. * checkBinding is just an equality check. The example of this is accessing this._expr_2 .

@taras
Copy link

taras commented Dec 14, 2016

Is it possible to see an entire compiled app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment