Fireship · @fireship

NGXS - Angular State Management

Uploaded April 10, 2018 · Length 12:00

NGXS - Angular State Management

Summary

A comparison of NGXS and NgRx state management libraries for Angular, focusing on the basics of NGXS and its benefits over NgRx.

  • ngxs vs ngrx
  • angular state management
  • ngxs tutorial
  • state management libraries
  • angular development

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:01

    today we're going to take a look at ng

  3. 0:04

    XS a new state management library that

  4. 0:06

    reimagines the way the Redux pattern

  5. 0:08

    should be applied and angular it gives

  6. 0:11

    us a global and mutable data store then

  7. 0:13

    components can select data from the

  8. 0:15

    store as an observable then dispatch

  9. 0:17

    actions to mutate the store the end

  10. 0:20

    result is a circular predictable flow of

  11. 0:22

    data that is especially beneficial for

  12. 0:24

    apps that have a complex data state in

  13. 0:27

    this episode we'll go through the basics

  14. 0:29

    of ng XS from the ground up if you're

  15. 0:31

    new make sure to LIKE and subscribe and

  16. 0:33

    grab the full source code from angular

  17. 0:34

    firebase comm so first we need to

  18. 0:37

    address the elephant in the room there's

  19. 0:39

    already a state management library for

  20. 0:41

    angular called ng R X which has become

  21. 0:43

    very popular by taking the

  22. 0:45

    implementation details of react Redux

  23. 0:47

    and applying them to angular but the

  24. 0:50

    problem is that angular has a type

  25. 0:51

    system and makes heavy use of

  26. 0:53

    object-oriented programming while react

  27. 0:55

    has no type system and makes heavy use

  28. 0:57

    of pure functions in order to strong

  29. 0:59

    type everything and maintain a strict

  30. 1:01

    separation of concerns and ng Rx we have

  31. 1:03

    to write a ton of boilerplate code code

  32. 1:06

    that is often very difficult to read

  33. 1:07

    especially for someone without an rxjs

  34. 1:10

    background while I'm a big fan of ng rx

  35. 1:12

    and one of its top donors I think ng XS

  36. 1:15

    addresses some of these concerns in a

  37. 1:17

    very elegant way so what I've done for

  38. 1:19

    this video is I built an app with ng XS

  39. 1:22

    and then I built the same exact app with

  40. 1:24

    ng Rx so we can compare them

  41. 1:25

    side-by-side

  42. 1:26

    the rest of this video will focus on the

  43. 1:29

    basics of ng XS but occasionally I'll

  44. 1:31

    flip over to this ng rx app just so you

  45. 1:33

    can see that differences and how the

  46. 1:35

    code is implemented and I'm not

  47. 1:37

    recommending one over the other just

  48. 1:38

    showing you a comparison between the two

  49. 1:40

    the app itself is called ng XS salad bar

  50. 1:44

    and it allows the user to create and

  51. 1:46

    customize a salad order if you look at

  52. 1:49

    the UI here you'll see everything

  53. 1:50

    highlighted in green is saved in the app

  54. 1:52

    store and everything with a solid

  55. 1:55

    outline border is triggering an action

  56. 1:57

    so you can see here we trigger actions

  57. 1:59

    that add toppings to the salad and then