Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Angular 2 Offline Compiler

Angular 2 Offline Compiler

Shuhei Kagawa

May 20, 2016
Tweet

More Decks by Shuhei Kagawa

Other Decks in Programming

Transcript

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

    ES2015+ → babel-angular2-app → babel-preset-angular2 → babel-plugin-angular2-annotations
  2. 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);
  3. 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);
  4. 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; }
  5. createInternal → create elements, texts and directives → set up

    listeners → set up subscriptions → call child views
  6. 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); }
  7. Benefits → Shorter bootstrap time → JS size: compiler and

    platform-browser-dynamic vs *.ngfactory.ts → Type-check your templates!
  8. 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