Fireship · @fireship

NgRx + Firestore

Uploaded November 17, 2017 · Length 10:20

NgRx + Firestore

Summary

Learn how to use NgRx with Firestore as a persistent back-end data source in Angular applications.

  • ngrx firestore
  • angular firestore
  • angular ngrx
  • firebase firestore
  • angularfire2
  • ngrx entity adapter
  • ngrx effects

Transcript preview

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

  1. 0:00

    a few weeks ago I showed you how to use

  2. 0:01

    ng rx entity adapt Paris today I'm going

  3. 0:04

    to build on this concept and show you

  4. 0:06

    how to use fire store as a persistent

  5. 0:08

    back-end data source you might be aware

  6. 0:10

    that angular fire version 5 has a new

  7. 0:12

    state changes method which we're going

  8. 0:14

    to take advantage of in this episode it

  9. 0:16

    makes it possible to keep track of when

  10. 0:17

    documents are added modified or removed

  11. 0:20

    if you want an example of how this might

  12. 0:22

    be used look no further than the

  13. 0:23

    firebase console itself if we add a new

  14. 0:25

    value to the database you'll see it

  15. 0:27

    flashes green first one second and the

  16. 0:29

    document itself is modified so it

  17. 0:30

    flashes orange if we remove the property

  18. 0:33

    then it flashes red the fire store web

  19. 0:36

    console happens to be built with ng rx

  20. 0:38

    which I learned by watching angular air

  21. 0:39

    episode 135 so make sure to check that

  22. 0:42

    out as well if you're new here click the

  23. 0:44

    subscribe button and follow along with

  24. 0:45

    the source code at angular firebase comm

  25. 0:48

    to get started I'm going to first show

  26. 0:51

    you how we have this app setup based on

  27. 0:52

    the previous video starting with the app

  28. 0:55

    module the main change we made is we

  29. 0:57

    installed angularfire 2 along with

  30. 0:59

    firestorm I'm also including the ng RX

  31. 1:02

    effects module and in the root just

  32. 1:04

    passing it an empty array if you're lost

  33. 1:07

    at this point make sure to go back and

  34. 1:08

    watch the ng RX entity video from there

  35. 1:11

    I'm going to go into our pizza feature

  36. 1:14

    module and I have a new file called

  37. 1:16

    pizza effects that we're going to create

  38. 1:18

    later we also import the effects module

  39. 1:20

    here but call for feature and pass it

  40. 1:22

    the pizza effects file the actual app

  41. 1:25

    we're building is just a collection of

  42. 1:27

    pizzas and the user has the ability to

  43. 1:29

    asynchronously update them from a status

  44. 1:31

    of cooking to delivered the thing that's

  45. 1:34

    interesting is that this app is going to

  46. 1:36

    listen for the state changes coming from

  47. 1:38

    angularfire 2 and then use entity

  48. 1:40

    adapters to update the local data store

  49. 1:43

    currently I've queried all the pizzas

  50. 1:45

    that have a status of cooking so if the

  51. 1:47

    status changes from anything other than

  52. 1:49

    cooking it should be removed from our

  53. 1:50

    local data store if we update the status

  54. 1:53

    from cooking to delivered you'll see

  55. 1:54

    that it gets removed from the local data

  56. 1:56

    store and that action is triggered here

  57. 1:58

    and redux dev tools the key takeaway