Angular 2 Offline Compiler

Angular 2 Offline Compiler

Ca0ab6e450f894e06652ee257df9d647?s=128

Shuhei Kagawa

May 20, 2016
Tweet

Transcript

  1. 3.

    Angular 2 & Me TypeScript-ish type annotations and decorators in

    ES2015+ → babel-angular2-app → babel-preset-angular2 → babel-plugin-angular2-annotations
  2. 13.
  3. 14.

    import { coreBootstrap, ReflectiveInjector } from '@angular/core'; import { browserPlatform,

    BROWSER_APP_STATIC_PROVIDERS } from '@angular/platform-browser'; import {AppNgFactory} from './app.ngfactory'; const appInjector = ReflectiveInjector.resolveAndCreate( BROWSER_APP_STATIC_PROVIDERS, browserPlatform().injector ); coreBootstrap(appInjector, AppNgFactory);
  4. 18.
  5. 21.

    app.ngfactory.ts class _View_App0 extends DebugAppView<any> { createInternal() {} detectsChangeInternal() {}

    } function viewFactory_App0(...): AppView<any> {} class _View_App_Host0 extends DebugAppView<any> { createInternal() {} } function viewFactory_App_Host0(...): AppView<any> {} export const AppNgFactory: ComponentFactory<App> = new ComponentFactory<App>('app', viewFactory_App_Host0, App);
  6. 23.

    createInternal(rootSelector: string): AppElement { var parentRenderNode =this.renderer .createViewRoot(this.declarationAppElement.nativeElement); this._text_0 =

    this.renderer .createText(parentRenderNode,'',this.debug(0,0,0)); this._expr_0 = import3.uninitialized; this.init([],[this._text_0],[],[]); return null; }
  7. 24.

    createInternal → create elements, texts and directives → set up

    listeners → set up subscriptions → call child views
  8. 26.

    detectChangesInternal(throwOnChange: boolean): void { this.detectContentChildrenChanges(throwOnChange); this.debug(0,0,0); var currVal_0: any =

    import4.interpolate(1,'Hello World ',this.context.user,''); if (import4.checkBinding(throwOnChange,this._expr_0,currVal_0)) { this.renderer.setText(this._text_0,currVal_0); this._expr_0 = currVal_0; } this.detectViewChildrenChanges(throwOnChange); }
  9. 28.

    Benefits → Shorter bootstrap time → JS size: compiler and

    platform-browser-dynamic vs *.ngfactory.ts → Type-check your templates!
  10. 29.

    Notes → Don't check in generated files → TypeScript 1.8:

    generate in src → TypeScript 1.9: use rootDirs → Expect a build system plugin instead of the CLI
  11. 31.