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

Successful with Signals: 3 Patterns for Your Ar...

Successful with Signals: 3 Patterns for Your Architecture

Manfred Steyer

September 03, 2024
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. Agenda • Austrian Desserts • Computed • Rendering Effects •

    Business Effects • RxJS Interop • Stores
  2. About me… Manfred Steyer, ANGULARarchitects.io (Remote) Angular Workshops and Consulting

    Google Developer Expert for Angular Blog, Books, Articles, and Talks about Angular Manfred Steyer
  3. Component With Signals 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>
  4. Component With Signals from = signal('Paris'); to = signal('London'); flightRoute

    = computed(() => this.from() + ' to ' + this.to());
  5. Why Signals as Events are Critical? Glitch-free property: Events might

    get lost Quickly leads to Effects with Signal Writes Chains of change and cycles?
  6. But … Angular APIs are more and more Signal-based Using

    Events behind Signal change might feel unnatural <input [(ngModel)]="mySignal" (change)="…">
  7. Overlapping Req. & Race Conditions Pancakes Sacher Cake Ice Cream

    Pancakes switchMap, mergeMap, concatMap, exhaustMap
  8. Overlapping Req. & Race Conditions Pancakes Sacher Cake Ice Cream

    Pancakes switchMap, mergeMap, concatMap, exhaustMap
  9. Stores Streamline Reactive Flow Component Store "Intention" Signal sync/ async

    computed() computed() Currently: Main Use Case for Signas Business Effects, Events, RxJS and/or RxJS
  10. More: Angular Architecture Workshop • Maintainable Architectures with Modern Angular

    • Strategic Design with Nx & Sheriff • Micro Frontends with Module Federation • Signals and Your Architecture: CD & Zone-less, NGRX & Signal Store, RxJS-Interop German Version: angulararchitects.io/workshop-de English Version: angulararchitects.io/workshop-en
  11. Conclusion Architecture Rule #1 Synchronously derive state where possible Architecture

    Rule #2 Avoid (rendering) effects propagating state and signal writes Architecture Rule #3 Stores make your reactive flow more manageable Component Store
  12. Conclusion Hint #1 Signals play well together with RxJS Hint

    #2 Avoid Race Conditions (e.g. RxJS and/or loading flag) Hint #3 Be aware of options and consequences of Business Effects