$30 off During Our Annual Pro Sale. View Details »

Lightweight Architectures With Angular's Latest...

Lightweight Architectures With Angular's Latest Innovations

Manfred Steyer

June 13, 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 b/w Domains, etc. on a folder basis

    Credits to: 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, ...featues: 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 @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { private

    flightService = inject(FlightService); private _flights = signal<Flight[]>([]); readonly flights = this._flights.asReadonly(); […] }
  15. @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); } […] }