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

[PL] Historia jednej migracji

Przemek
January 10, 2018

[PL] Historia jednej migracji

Migrating to Angular 5 - lessons learned.

Przemek

January 10, 2018
Tweet

More Decks by Przemek

Other Decks in Technology

Transcript

  1. 1. Projekt oparty o AngularJS 3. Projekt oparty o Angulara

    2. Etap przejściowy - aplikacja hybrydowa
  2. Migracja w moim przypadku (full): root component należy do mnie

    chcę przemigrować co tylko możliwe części nienależące do mnie integruję poprzez upgrade
  3. UpgradeModule w akcji import { UpgradeModule } from '@angular/upgrade/static'; @NgModule({

    … }) export class AppModule { constructor( private upgradeModule: UpgradeModule ) { } ngDoBootstrap() { this.upgradeModule .bootstrap(document.body, ['people-ui']); } }
  4. Migracja serwisów angular.module('people-ui') .service('QueryService', QueryService); function QueryService() { this.getFiltersQuery =

    function(currentState) { return { aggregations: getCurrentState(), query: getAdditionalQueryProperties() }; } }
  5. Migracja serwisów import { Injectable } from '@angular/core'; @Injectable() export

    class QueryService { getFiltersQuery(currentState) { return { aggregations: this.getAggregations(), query: this.getQuery() }; } }
  6. A jeśli serwis nie należy do mnie? import { InjectionToken

    } from "@angular/core"; export const ACCESS_SERVICE_TOKEN = new InjectionToken<any>('ACCESS_SERVICE'); export const accessServiceProvider = { provide: ACCESS_SERVICE_TOKEN, deps: ['$injector'], useFactory: injector => injector.get('accessService') }
  7. A jeśli serwis nie należy do mnie? import { Injectable

    } from '@angular/core'; @Injectable() export class WantToUseAngularJsService { constructor( @Inject(ACCESS_SERVICE_TOKEN) private service: any ) { } }
  8. A jeśli serwis nie należy do mnie? @NgModule({ imports: [

    CommonModule ], providers: [ accessServiceProvider ] }) export class AngularJsModule { }
  9. Migracja komponentów @Component({ selector: 'my-component', templateUrl: './my.component.html', }) export class

    MyComponent implements OnInit, OnDestroy { ngOnInit() { } ngOnDestroy() { } }
  10. A nie, spoko… const { transformTemplate } = require('create-angular-template') const

    angularTemplate = transformTemplate(template, options) npm install create-angular-template
  11. UpgradeComponent @Directive({ selector: 'app-old-component' }) export class OldComponentFacade extends UpgradeComponent

    { @Input() color: string; constructor(elementRef: ElementRef, injector: Injector) { super('srOldComponent', elementRef, injector); } }
  12. Facade/Wrapper @Directive({ selector: 'app-popover' }) export class PopoverFacade extends UpgradeComponent

    { @Input() label: string; constructor(elementRef: ElementRef, injector: Injector) { super(’srPopoverFacade', elementRef, injector); } }