Fireship · @fireship
RxJS Top Ten - Code This, Not That
Uploaded March 25, 2019 · Length 14:44
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.
- 0:00
[Music]
- 0:06
one of the most difficult but also most
- 0:08
rewarding javascript libraries to learn
- 0:10
is rxjs it's a tool that helps us
- 0:12
control data as it flows through the
- 0:14
dimension of time in today's episode of
- 0:16
code that's notthat you'll learn ten
- 0:17
fundamental concepts in rxjs and how to
- 0:19
avoid the bad stuff if you're new here
- 0:21
like and subscribe and leave me a
- 0:23
comment below for a chance to win this
- 0:24
t-shirt next week rxjs is getting pretty
- 0:26
popular these days in fact it gets more
- 0:28
daily npm downloads than angular
- 0:30
reactive view and the only functional
- 0:32
library that i'm aware of it's bigger is
- 0:33
low - and the reason it's so popular is
- 0:35
because javascript alone doesn't give us
- 0:37
quite everything we would like to work
- 0:39
with asynchronous streams of data we
- 0:41
have promises but they only work with a
- 0:42
single ASIC value so we use callbacks
- 0:44
for real time streams but you've
- 0:46
probably heard the term callback hell
- 0:47
rxjs addresses these issues and gives us
- 0:50
a powerful functional library for
- 0:51
dealing with strings and when I say
- 0:53
stream I'm talking about any data source
- 0:55
that unfolds over the dimension of time
- 0:57
things like data from firebase Dom
- 0:59
events WebSockets file uploads etc the
- 1:02
first thing you'll need to do is install
- 1:04
rxjs I'm currently running version 6.4
- 1:06
now I'm just using vanilla JavaScript
- 1:08
with webpack but feel free to follow
- 1:10
along with your favorite JavaScript
- 1:12
framework the most fundamental class in
- 1:14
rxjs is the observable you can think of
- 1:16
it as a wrapper for some data that can
- 1:18
be subscribed to and then the subscriber
- 1:20
will be notified anytime the data
- 1:21
changes when working with rxjs you
- 1:23
should think of yourself as a plumber
- 1:25
and I mean that in the most literal
- 1:26
sense because an observable is
- 1:27
essentially a pipe for data and rxjs
- 1:30
gives you all kinds of tools to modify
- 1:31
those pipes let's go ahead and create
- 1:33
our first observable but first we need
- 1:35
to import the rxjs library and there's a
- 1:37
right and a wrong way to do this
- 1:39
currently I'm doing it the wrong way by
- 1:41
using import star as our X but that's
- 1:43
going to cause the entire library to be
- 1:45
bundled up in our code you can see down
- 1:47
here we have a bundle size of 47
- 1:49
kilobytes but rxjs is a tree shakable
- 1:51
library which means we only have to
- 1:53
import the code that we actually need so
- 1:55
when working with rxjs you should only
- 1:57
import the classes and operators that
- 1:59
you actually need in your source code


