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

Lightweight Architectures: With Angular's Lates...

Lightweight Architectures: With Angular's Latest Innovations

Manfred Steyer

June 22, 2023
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer NgModules + EcmaScript Modules import { NgModule } from

    '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; […] @NgModule({ imports: [BrowserModule, OtherModule], declarations: [AppComponent, OtherComponent, OtherDirective], providers: [], bootstrap: [AppComponent], }) export class AppModule {} TypeScript Modules Angular Modules
  2. @ManfredSteyer @Component({ standalone: true, imports: [ […], FlightCardComponent, CityPipe, CityValidator,

    ], selector: 'flight-search', templateUrl: '…' }) export class FlightSearchComponent { […] }
  3. @ManfredSteyer Restricting Access on a folder basis Tech Lead Rainer

    Hahnekamp, AngularArchitects @softarc/eslint-plugin-sheriff
  4. @ManfredSteyer export function provideLogger(config: LoggerConfig): Provider[] { return [ LoggerService,

    { provide: LoggerConfig, useValue: config }, { provide: LogFormatter, useValue: config.formatter }, ]; }
  5. @ManfredSteyer export function provideLogger(config: LoggerConfig): Provider[] { return [ LoggerService,

    { provide: LoggerConfig, useValue: config }, { provide: LogFormatter, useValue: config.formatter }, ]; }
  6. @ManfredSteyer export function provideLogger(config: LoggerConfig): EnvironmentProviders { return makeEnvironmentProviders([ LoggerService,

    { provide: LoggerConfig, useValue: config }, { provide: LogFormatter, useValue: config.formatter }, ]); }
  7. @ManfredSteyer export function provideLogger( config: LoggerConfig, ...features: LoggerFeature[] ): EnvironmentProviders

    { return makeEnvironmentProviders([ LoggerService, […], features?.map(f => f.providers) ]); }
  8. @ManfredSteyer @Component({ […] }) export class FlightEditComponent { @Input() id

    = ''; @Input() showDetails = ''; […] } All you need for getting routing parameters!
  9. @ManfredSteyer export const APP_ROUTES: Routes = [ { path: 'home',

    component: HomeComponent, }, { path: 'flight-booking', loadChildren: () => import('./[…]/flight-booking.routes') .then(m => m.FLIGHT_BOOKING_ROUTES) }, ];
  10. @ManfredSteyer export const APP_ROUTES: Routes = [ { path: 'home',

    component: HomeComponent, }, { path: 'flight-booking', loadChildren: () => import('./[…]/flight-booking.routes') .then(m => m.FLIGHT_BOOKING_ROUTES) }, ]; Lazy routing config as default expert
  11. @ManfredSteyer export const APP_ROUTES: Routes = [ […] { path:

    'flight-booking', canActivate: [() => inject(AuthService).isAuthenticated()], component: FlightBookingComponent }, ]
  12. @ManfredSteyer export const APP_ROUTES: Routes = [ […] { path:

    'flight-booking', canActivate: [() => inject(AuthService).isAuthenticated()], component: FlightBookingComponent }, ]
  13. @ManfredSteyer export const APP_ROUTES: Routes = [ […] { path:

    'flight-booking', canActivate: [() => inject(AuthService).isAuthenticated()], resolve: { flights: () => inject(FlightService).findAll() }, component: FlightBookingComponent }, ]
  14. @ManfredSteyer flights: Flight[] = []; const flights = await this.flightService.findAsPromise(from,

    to); this.flights = flights; <div *ngFor="let f of flights"> <flight-card [item]="f" /> </div>
  15. @ManfredSteyer flights = signal<Flight[]>([]); const flights = await this.flightService.findAsPromise(from, to);

    this.flights.set(flights); <div *ngFor="let f of flights()"> <flight-card [item]="f" /> </div>
  16. @ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { private

    flightService = inject(FlightService); private _flights = signal<Flight[]>([]); readonly flights = this._flights.asReadonly(); […] }
  17. @ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { private

    flightService = inject(FlightService); private _flights = signal<Flight[]>([]); readonly flights = this._flights.asReadonly(); async load(from: string, to: string) { const flights = await this.flightService.findPromise(from, to); this._flights.set(flights); } […] }