Slide 1

Slide 1 text

AngularArchitects.io | @ManfredSteyer | @RainerHahnekamp 3 Effective Rules for Using Signals in Angular

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Agenda • Austrian Desserts • Computed • Resource API • Effects • Stores

Slide 6

Slide 6 text

Result 3 Rules (of thumb)

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Austrian Desserts: Example App

Slide 9

Slide 9 text

Demo

Slide 10

Slide 10 text

Computed: Extremely Unterrated!

Slide 11

Slide 11 text

Reactive Programming: Paradigm Shift!

Slide 12

Slide 12 text

Marble Run

Slide 13

Slide 13 text

Marble Run Data Binding

Slide 14

Slide 14 text

Reactive Flow with Computed desserts = signal([]); ratings = signal({}); ratedDesserts = computed(() => this.toRated(this.desserts(), this.ratings()));

Slide 15

Slide 15 text

Reactive Flow with Computed desserts = signal([]); ratings = signal({}); ratedDesserts = computed(() => this.toRated(this.desserts(), this.ratings()));

Slide 16

Slide 16 text

Demo Branch: 02a-input-signals

Slide 17

Slide 17 text

Reactive Flow with Computed desserts = signal([]); ratings = signal({}); ratedDesserts = computed(() => this.toRated(this.desserts(), this.ratings())); originalName = signal(''); englishName = signal(''); Load Desserts

Slide 18

Slide 18 text

Resource API

Slide 19

Slide 19 text

Resource API dessertsResource = resource({ request: this.dessertsCriteria, loader: (param) => { return this.#dessertService.findPromise(param.request); } }); Experimental in Angular 19

Slide 20

Slide 20 text

Resource API dessertsResource = resource({ request: this.dessertsCriteria, loader: (param) => { return this.#dessertService.findPromise(param.request); } }); dessertsCriteria = computed(() => ({ originalName: this.originalName(), englishName: this.englishName(), })); desserts = this.dessertsResource.value; ratedDesserts = computed(() => this.toRated(this.desserts, …));

Slide 21

Slide 21 text

Resource Prevents Race Conditions Pancakes Sacher Cake Ice Cream Pancakes

Slide 22

Slide 22 text

Resource Prevents Race Conditions Pancakes Sacher Cake Ice Cream Pancakes „switchMap semantics“

Slide 23

Slide 23 text

Demo Branch: 2c-resource

Slide 24

Slide 24 text

Architecture Rule #1 Derive state where possible

Slide 25

Slide 25 text

Effects

Slide 26

Slide 26 text

Connecting Reactive and Imperative World

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Ideal-typical Tasks • Drawing on a canvas • Manual DOM manipulations • Logging • Synching with LocalStore Stuff, you cannot do with data binding Rendering (and similar tasks …)

Slide 29

Slide 29 text

Demo Branch: 04c-effects

Slide 30

Slide 30 text

Architecture Rule #2 Avoid effects triggering business logic

Slide 31

Slide 31 text

Instead: Reactive Helpers like Resource API @ngrx/signals ngxtension Your Own …

Slide 32

Slide 32 text

Reactive Helpers: Effects Under the Hood

Slide 33

Slide 33 text

Demo Branch: 08b-details

Slide 34

Slide 34 text

Stores

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Stores Streamline Reactive Flow Component Store "Intention" Signal sync/ async computed() computed()

Slide 39

Slide 39 text

Demo Branch: 08b-details

Slide 40

Slide 40 text

Architecture Rule #3 Stores make your reactive flow more manageable

Slide 41

Slide 41 text

Free eBook (6th Edition) angularArchitects.io/ebook

Slide 42

Slide 42 text

Conclusion Architecture Rule #1 Derive state where possible Architecture Rule #2 Avoid effects triggering business logic Architecture Rule #3 Stores make your reactive flow more manageable

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Marble Run

Slide 45

Slide 45 text

AngularArchitects.io Slides & Examples ManfredSteyer