Fireship · @fireship

Learn @ngrx/entity and Feature Modules

Uploaded October 26, 2017 · Length 9:50

Learn @ngrx/entity and Feature Modules

Summary

Learn how to use @ngrx/entity and feature modules in Angular to manage global data and perform CRUD operations.

  • ngrx entity
  • angular feature modules
  • ngrx store
  • crud operations
  • angular state management

Transcript preview

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

  1. 0:00

    the worst thing about ng Rx is the sheer

  2. 0:02

    amount of code that it takes to build

  3. 0:04

    anything but you're rewarded for that

  4. 0:05

    extra effort with a global data store

  5. 0:07

    that's easy to test and debug and cool

  6. 0:10

    things like the Redux dev tools here on

  7. 0:12

    the right to address the amount of

  8. 0:14

    boilerplate code in ng rx they recently

  9. 0:16

    released a new package called entity it

  10. 0:18

    provides a standardized way to manage

  11. 0:20

    collections of objects and perform basic

  12. 0:22

    credence on them in this episode I'm

  13. 0:25

    going to use entity to build this basic

  14. 0:27

    Pizza ordering app here on the left and

  15. 0:29

    I'm also going to show you how to build

  16. 0:31

    feature modules with ng Rx if you're new

  17. 0:33

    to my channel make sure to subscribe and

  18. 0:35

    if you're new to ng Rx check out my

  19. 0:37

    previous QuickStart tutorial which is a

  20. 0:39

    much easier introduction into these

  21. 0:41

    concepts I am starting out with a brand

  22. 0:44

    new angular app called ng rx pizza so

  23. 0:46

    will CD into that directory and then

  24. 0:48

    install store and entity from there I

  25. 0:52

    create a new module called pizza this

  26. 0:54

    will be our feature module then I'm

  27. 0:56

    going to add a single component to it

  28. 0:57

    we'll just call that component pizza

  29. 0:59

    order then we'll open the module up and

  30. 1:02

    import the store module then I'm

  31. 1:05

    importing a reducer that has not yet

  32. 1:07

    been created but we're going to get into

  33. 1:09

    that a little bit later we're going to

  34. 1:11

    add the store module to the import

  35. 1:12

    section and then call for feature with

  36. 1:15

    the name of our reducer and the reducer

  37. 1:17

    itself

  38. 1:18

    this approach is trivial here because we

  39. 1:20

    only have one feature but when you have

  40. 1:21

    multiple features this will help keep

  41. 1:23

    your code much more organized so the

  42. 1:25

    next step is to create a directory

  43. 1:27

    called reducers in the app directory and

  44. 1:29

    then inside that create a file called

  45. 1:31

    index is then we'll import action

  46. 1:34

    reducer map and our pizza reducer and

  47. 1:37

    then we'll export all of our reducers as

  48. 1:40

    a single constant in this example we

  49. 1:42

    only have one but you can imagine how

  50. 1:43

    much more convenient this would be if

  51. 1:45

    you had 10 different reducers to manage

  52. 1:47

    at this point we're ready to jump over

  53. 1:49

    to the app module then import the store

  54. 1:52

    module as well as optionally the dev

  55. 1:54

    tools module and then we're going to

  56. 1:57

    import our pizza module that we just

  57. 1:59

    created as well as the reducers index