Slide 1

Slide 1 text

State management with NgRx SignalStore Manage state in a reactive way Daniel Sogl @sogldaniel Softwarearchitekt

Slide 2

Slide 2 text

• Why State Management? • What is NgRx? • SignalStore • Setup • withState • withComputed • withMethods • … • Exercises • Create custom Signal Store Features • Signal Store Architecture Agenda

Slide 3

Slide 3 text

Daniel Sogl • Software architect @ Thinktecture AG • Focus: Angular, Capacitor and AI-Coding • Socials: https://linktr.ee/daniel_sogl About me

Slide 4

Slide 4 text

• Web Apps have different States • UI-State • Storage-State • Data-State • URL-State • Multiple Data Sources • Services • WebSocket • ... • Multiple Developers • Different solutions for the same problems Why State Management with Stores?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

In Angular • No State Management • Rxjs based State Management • BehaviorSubjects • Readonly Observables • Signal Based State Management • State Management Libraries • NgRx (Redux, Component Store, Signal Store) • Ngxs • Akita • … State Management Solutions

Slide 7

Slide 7 text

• State is handled internally • Accessible trough read-only Observable • Subscription with Async-Pipe • Immutable Changes Rxjs Based Store

Slide 8

Slide 8 text

• State is handled internally • No subscription handling needed • No third-party library needed Signal Based Store

Slide 9

Slide 9 text

NgRx The defector standard in Angular • Redux Pattern in Angular • Reactive with Observables or Signals • Component Store as lightweight alternative for component-based state management

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Lightweight Reactive State Management • Standalone Library • Signal Based • Functional Based • Extendable • Rxjs compatible • Helper Functions • SignalState • DeepComputed NgRx Signal Store

Slide 13

Slide 13 text

Installation

Slide 14

Slide 14 text

• signalStore • withState • withComputed • withMethods • withProps • withHooks • withEntities • signalStoreFeature Signal Store Methods

Slide 15

Slide 15 text

Define the Store

Slide 16

Slide 16 text

Use the Store

Slide 17

Slide 17 text

Share Dependencies • Share Injectables or other Dependencies • Can be used across the Store without the need to reinject

Slide 18

Slide 18 text

Lifecycle Hooks / Watch State

Slide 19

Slide 19 text

• Clone Repo: https://github.com/danielsogl/ngrx-signal-store-workshop • Refactor the Todo component to use a Signal Store (exercises/03-todo-store) Exercise 1

Slide 20

Slide 20 text

rxMethod • Opt-in integration with rxjs • Manges side-effects • Can be used standalone without the signal store • No manual subscription required

Slide 21

Slide 21 text

• Manage multiple Entities • Use Entity Update Functions • setEntity / setEntities • addEntity / addEntities • removeEntity / removeEntities • updateEntity / updateEntities • updateAllEntities • Access Data trough Records • Normalize State (normalizr) Entity Adapter

Slide 22

Slide 22 text

• Reusable Features • Type Safe • Atomic updates with custom update functions • https://github.com/angular- architects/ngrx-toolkit Signal Store Features

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Exercise 2 • Refactor the Movies search to use a signal store (exercises/02-media-store) • Try out the rxMethod • Try out creating a reusable withSnackbar signal store feature

Slide 25

Slide 25 text

• Avoid global stores that share everything with everyone • Split larger stores into smaller stores • Separation of concerns • Share functionality's trough features instead of store injections Signal Store Architecture

Slide 26

Slide 26 text

• The Signal Store provides a lightweight, reactive state management solution • Build on top of Angular Signals API • Can be used on a component, feature or global level • Does not replace Redux (remember Signals are not made for handling events) • Reusable features using Signal Store Features Conclusion

Slide 27

Slide 27 text

No content