Fireship · @fireship

Angular Ngrx Effects with Firebase Database

Uploaded August 30, 2017 · Length 8:57

Angular Ngrx Effects with Firebase Database

Summary

Learn how to implement Angular Ngrx Effects with Firebase Database, including setting up the app, creating post effects and reducer, and handling side effects.

  • angular ngrx effects
  • firebase database
  • ngrx store
  • angular firebase
  • side effects
  • angular effects

Transcript preview

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

  1. 0:00

    in my last video I showed you how to

  2. 0:01

    implement Redux patterns and angular

  3. 0:03

    using ng rx store if you're brand new to

  4. 0:06

    redux I recommend checking out that

  5. 0:07

    video first if you haven't already if

  6. 0:09

    you're an angular firebase Pro member

  7. 0:11

    I'd like to take a second to say thank

  8. 0:13

    you for supporting this project and let

  9. 0:15

    you know that we're using your

  10. 0:16

    investment to support other open-source

  11. 0:18

    projects such as ng rx I pledged $100

  12. 0:21

    per month and will do the same for other

  13. 0:23

    exceptional angular projects and content

  14. 0:25

    creators getting back to this episode

  15. 0:27

    we're going to build an ng rx angular

  16. 0:30

    app that uses firebase on the backend

  17. 0:32

    we'll be able to retrieve as well as

  18. 0:34

    update post on the firebase real-time

  19. 0:36

    database when working with firebase we

  20. 0:39

    have to worry about the side effects

  21. 0:40

    that come with working with a third

  22. 0:42

    party API ng Rx has a package called

  23. 0:45

    effects that serves just this purpose we

  24. 0:47

    can install it using NPM at this point

  25. 0:50

    you should have angularfire 2 for

  26. 0:52

    firebase installed you can find

  27. 0:53

    instructions for that on the official

  28. 0:55

    repo now let's look at why we need to

  29. 0:57

    use effects in the first place

  30. 0:58

    consider the following example of a pure

  31. 1:01

    function it's considered a pure because

  32. 1:03

    it only affects data within its own

  33. 1:04

    scope it would be considered impure if

  34. 1:07

    we defined a variable

  35. 1:08

    outside of that function and then used

  36. 1:10

    it inside the function scope what often

  37. 1:12

    happens in the real world is we have an

  38. 1:14

    impure function that will do an

  39. 1:15

    operation on the database causing a

  40. 1:17

    chain of different side effects in the

  41. 1:18

    application the goal of ng rx effects is

  42. 1:21

    to isolate functions like this to make

  43. 1:23

    them behave more or less like a pure

  44. 1:25

    function let's start coding this up in

  45. 1:27

    angular in the app module we're going to

  46. 1:30

    need the angular fired database as well

  47. 1:32

    as the effects module store and store

  48. 1:35

    dev tools then we're going to create our

  49. 1:37

    own post effects and post reducer in the

  50. 1:39

    upcoming steps post effects behave just

  51. 1:42

    like an angular service so when we

  52. 1:44

    import them we add them to an array and

  53. 1:46

    the effects module then the reducer is

  54. 1:48

    added to the store module now before

  55. 1:51

    going any further I want to show you how

  56. 1:52

    I have this app organized I have a

  57. 1:54

    folder for actions effects models and

  58. 1:57

    reducers you'll most likely want a

  59. 1:59

    similar organization to this for each