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

3 Effective Rules for Using Signals in Angular

3 Effective Rules for Using Signals in Angular

Manfred Steyer

November 05, 2024
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. 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
  2. Reactive Flow with Computed desserts = signal<Dessert[]>([]); ratings = signal<DessertIdToRatingMap>({});

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

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

    ratedDesserts = computed(() => this.toRated(this.desserts(), this.ratings())); originalName = signal(''); englishName = signal(''); Load Desserts
  5. Resource API dessertsResource = resource({ request: this.dessertsCriteria, loader: (param) =>

    { return this.#dessertService.findPromise(param.request); } }); Experimental in Angular 19
  6. 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, …));
  7. 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 …)
  8. Conclusion Architecture Rule #1 Derive state where possible Architecture Rule

    #2 Avoid effects propagating state and Signal writes Architecture Rule #3 Stores make your reactive flow more manageable