Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Lightweight Architectures: With Angular's Lates...

Lightweight Architectures: With Angular's Latest Innovations

Manfred Steyer

April 26, 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 @Component({ standalone: true, imports: [ […], FlightCardComponent, CityPipe, CityValidator,

    ], selector: 'flight-search', templateUrl: '…' }) export class FlightSearchComponent { […] }
  4. @ManfredSteyer Restricting Access b/w Domains, etc. on a folder basis

    Credits to: Rainer Hahnekamp, AngularArchitects @softarc/eslint-plugin-sheriff
  5. @ManfredSteyer → @Component({ standalone: true, selector: 'app-root', imports: [ […]

    TicketsModule, ], templateUrl: '…' }) export class AppComponent { }
  6. @ManfredSteyer → @Component({ standalone: true, selector: 'app-root', imports: [ […]

    TicketsModule, ], templateUrl: '…' }) export class AppComponent { }
  7. @ManfredSteyer export function provideLogger(config: LoggerConfig): Provider[] { return [ LoggerService,

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

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

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

    { return makeEnvironmentProviders([ LoggerService, […], features?.map(f => f.providers) ]); }
  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 export const authInterceptor: HttpInterceptorFn = (req, next) => {

    if (req.url.startsWith('https://[…]/')) { const headers = req.headers.set('Authorization', 'Bearer 12345'); req = req.clone({headers}); } […] }
  15. @ManfredSteyer export const authInterceptor: HttpInterceptorFn = (req, next) => {

    if (req.url.startsWith('https://[…]/')) { const headers = req.headers.set('Authorization', 'Bearer 12345'); req = req.clone({headers}); } return next(req); }
  16. @ManfredSteyer Zone.js: Monkey Patching After Event Handler: Inform Angular CD

    Checks Components all components (default) or selected ones (OnPush)
  17. @ManfredSteyer Zone.js: Magic Zone.js: ~100K Cannot patch async/await coarse grained

    CD e.g. Components are always checked as a whole, even if only a tiny fraction changed
  18. @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>
  19. @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>
  20. @ManfredSteyer Fine-grained and Zone-less CD Convertible to Observables and vice

    versa! No need to unsubscribe! No need to update code!