Slide 1

Slide 1 text

@ManfredSteyer ManfredSteyer Architectures with Angular Signals ngBucharest

Slide 2

Slide 2 text

@ManfredSteyer Signal as Producer 4711 Consumer read set notify 4712

Slide 3

Slide 3 text

@ManfredSteyer flights = signal([]); const flights = await this.flightService.findAsPromise(from, to); this.flights.set(flights);

Slide 4

Slide 4 text

@ManfredSteyer Simple Reactive Building Block Fine-grained CD Zone-less CD Interop with RxJS No need to unsubscribe

Slide 5

Slide 5 text

@ManfredSteyer

Slide 6

Slide 6 text

@ManfredSteyer

Slide 7

Slide 7 text

@ManfredSteyer

Slide 8

Slide 8 text

@ManfredSteyer

Slide 9

Slide 9 text

@ManfredSteyer

Slide 10

Slide 10 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] private _flights = signal([]); readonly flights = this._flights.asReadonly(); async load(from: string, to: string) { const flights = await […]; this._flights.set(flights); } }

Slide 11

Slide 11 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] private _flights = signal([]); readonly flights = this._flights.asReadonly(); async load(from: string, to: string) { const flights = await […]; this._flights.set(flights); } }

Slide 12

Slide 12 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] private _flights = signal([]); readonly flights = this._flights.asReadonly(); private _from = signal('Hamburg'); readonly from = this._from.asReadonly(); private _to = signal('Graz'); readonly to = this._to.asReadonly(); […] }

Slide 13

Slide 13 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] private state = signal({ from: 'Hamburg', to: 'Graz', flights: [] as Flight[], […] }); […] }

Slide 14

Slide 14 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] private state = signal({ from: 'Hamburg', to: 'Graz', flights: [] as Flight[], […] }); flights = computed(() => this.state().flights); from = computed(() => this.state().from); […] }

Slide 15

Slide 15 text

@ManfredSteyer

Slide 16

Slide 16 text

@ManfredSteyer

Slide 17

Slide 17 text

@ManfredSteyer select(selector) selectSignal(selector)

Slide 18

Slide 18 text

@ManfredSteyer

Slide 19

Slide 19 text

@ManfredSteyer

Slide 20

Slide 20 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { private state = signalState({ from: 'Paris', to: 'London', flights: [] as Flight[], basket: {} as Record, }); flights = this.state.flights; from = this.state.from; […] }

Slide 21

Slide 21 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] selected = selectSignal( () => this.flights().filter((f) => this.basket()[f.id]); […] }

Slide 22

Slide 22 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] selected2 = selectSignal( this.flights, this.basket, (flights, basket) => flights.filter((f) => basket[f.id]) ); […] }

Slide 23

Slide 23 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] updateCriteria(from: string, to: string): void { patchState(this.state, { from, to }); } […] }

Slide 24

Slide 24 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] updateCriteria(from: string, to: string): void { patchState(this.state, state => ({ ...state, from, to })); } […] }

Slide 25

Slide 25 text

@ManfredSteyer @Injectable({ providedIn: 'root' }) export class FlightBookingFacade { […] updateCriteria(from: string, to: string): void { patchState(this.state, updateRoute(from, to)); } […] } function updateRoute(from: string, to: string) { return (state: T) => ({ ...state, from, to }) }

Slide 26

Slide 26 text

@ManfredSteyer

Slide 27

Slide 27 text

@ManfredSteyer export const FlightBookingStore = signalStore( { providedIn: 'root' }, […] );

Slide 28

Slide 28 text

@ManfredSteyer export const FlightBookingStore = signalStore( { providedIn: 'root' }, withState({ from: 'Paris', to: 'London', […] }), […] );

Slide 29

Slide 29 text

@ManfredSteyer export const FlightBookingStore = signalStore( { providedIn: 'root' }, withState({ from: 'Paris', to: 'London', […] }), withSignals(([…]) => ({ […] })), withMethods(([…]) => ({ })), withHooks({ […] }), withCallState() );

Slide 30

Slide 30 text

@ManfredSteyer

Slide 31

Slide 31 text

@ManfredSteyer const BooksStore = signalStore( withEntities({ collection: 'book' }), withEntities({ collection: 'author' }) );

Slide 32

Slide 32 text

@ManfredSteyer const BooksStore = signalStore( withLoadEntities(BookService), withLoadEntities(AuthorService), );

Slide 33

Slide 33 text

@ManfredSteyer Free eBook (5th Edition) ANGULARarchitects.io/book Module Federation & Nx

Slide 34

Slide 34 text

@ManfredSteyer • Maintainable Architectures • 🆕🔥 Standalone Components & APIs • Micro Frontends and Module Federation • 🆕🔥 Signals and Your Architecture: CD, NGRX, RxJS-Interop Public or Company Training, Remote or On-Site Next: Nov 27 to Nov 30, 2023 https://www.angulararchitects.io

Slide 35

Slide 35 text

@ManfredSteyer Services + Signals equal NGRX NGRX Signal Store Different Flavors Custom Features

Slide 36

Slide 36 text

@ManfredSteyer d Slides & Examples Remote Company Workshops and Consulting http://angulararchitects.io