Fireship · @fireship

RxJS Top Ten - Code This, Not That

Uploaded March 25, 2019 · Length 14:44

RxJS Top Ten - Code This, Not That

Summary

rxjs library basics, observables, subscriptions, hot and cold observables, and how to create and manage them in JavaScript.

  • rxjs library
  • javascript observables
  • rxjs subscriptions
  • hot observables
  • cold observables
  • rxjs subjects
  • rxjs behavior subjects

Transcript preview

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

  1. 0:00

    [Music]

  2. 0:06

    one of the most difficult but also most

  3. 0:08

    rewarding javascript libraries to learn

  4. 0:10

    is rxjs it's a tool that helps us

  5. 0:12

    control data as it flows through the

  6. 0:14

    dimension of time in today's episode of

  7. 0:16

    code that's notthat you'll learn ten

  8. 0:17

    fundamental concepts in rxjs and how to

  9. 0:19

    avoid the bad stuff if you're new here

  10. 0:21

    like and subscribe and leave me a

  11. 0:23

    comment below for a chance to win this

  12. 0:24

    t-shirt next week rxjs is getting pretty

  13. 0:26

    popular these days in fact it gets more

  14. 0:28

    daily npm downloads than angular

  15. 0:30

    reactive view and the only functional

  16. 0:32

    library that i'm aware of it's bigger is

  17. 0:33

    low - and the reason it's so popular is

  18. 0:35

    because javascript alone doesn't give us

  19. 0:37

    quite everything we would like to work

  20. 0:39

    with asynchronous streams of data we

  21. 0:41

    have promises but they only work with a

  22. 0:42

    single ASIC value so we use callbacks

  23. 0:44

    for real time streams but you've

  24. 0:46

    probably heard the term callback hell

  25. 0:47

    rxjs addresses these issues and gives us

  26. 0:50

    a powerful functional library for

  27. 0:51

    dealing with strings and when I say

  28. 0:53

    stream I'm talking about any data source

  29. 0:55

    that unfolds over the dimension of time

  30. 0:57

    things like data from firebase Dom

  31. 0:59

    events WebSockets file uploads etc the

  32. 1:02

    first thing you'll need to do is install

  33. 1:04

    rxjs I'm currently running version 6.4

  34. 1:06

    now I'm just using vanilla JavaScript

  35. 1:08

    with webpack but feel free to follow

  36. 1:10

    along with your favorite JavaScript

  37. 1:12

    framework the most fundamental class in

  38. 1:14

    rxjs is the observable you can think of

  39. 1:16

    it as a wrapper for some data that can

  40. 1:18

    be subscribed to and then the subscriber

  41. 1:20

    will be notified anytime the data

  42. 1:21

    changes when working with rxjs you

  43. 1:23

    should think of yourself as a plumber

  44. 1:25

    and I mean that in the most literal

  45. 1:26

    sense because an observable is

  46. 1:27

    essentially a pipe for data and rxjs

  47. 1:30

    gives you all kinds of tools to modify

  48. 1:31

    those pipes let's go ahead and create

  49. 1:33

    our first observable but first we need

  50. 1:35

    to import the rxjs library and there's a

  51. 1:37

    right and a wrong way to do this

  52. 1:39

    currently I'm doing it the wrong way by

  53. 1:41

    using import star as our X but that's

  54. 1:43

    going to cause the entire library to be

  55. 1:45

    bundled up in our code you can see down

  56. 1:47

    here we have a bundle size of 47

  57. 1:49

    kilobytes but rxjs is a tree shakable

  58. 1:51

    library which means we only have to

  59. 1:53

    import the code that we actually need so

  60. 1:55

    when working with rxjs you should only

  61. 1:57

    import the classes and operators that

  62. 1:59

    you actually need in your source code