Fireship · @fireship
RxJS Quick Start with Practical Examples
Uploaded September 12, 2017 · Length 15:33
Summary
This video teaches how to use RxJS with practical examples, covering observables, hot and cold observables, and various operators such as map, do, and filter.
- rxjs
- reactive programming
- observables
- rxjs operators
- javascript
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
reactive X has revolutionized the way
- 0:02
modern developers think about building
- 0:03
apps it allows us to treat all data as a
- 0:06
stream as it unfolds through the
- 0:07
dimension of time in this lesson I'm
- 0:10
going to cover about 25 different ways
- 0:11
you can use our XJS so you have a solid
- 0:13
foundation to use it in your own
- 0:15
projects for this tutorial I've just
- 0:17
created a basic HTML page and imported
- 0:20
the rxjs script from a CDN in the head
- 0:22
of that page then we'll write all of our
- 0:24
custom code in this lesson J's file and
- 0:27
import that in the body of the page then
- 0:29
inside lesson Jas I'm creating a helper
- 0:31
function that will just append the
- 0:33
results from an observable to the
- 0:34
browser on the right side here so when
- 0:36
you see me use the print function it's
- 0:38
to add the values to the browser here on
- 0:39
the right the first thing we're going to
- 0:41
talk about is the observable and I think
- 0:43
the easiest way to think about it is
- 0:44
just an array that gets built over time
- 0:47
and you can loop over this array in the
- 0:49
dimension of time by subscribing to it
- 0:51
the first thing we're gonna do is create
- 0:53
an observable from scratch
- 0:55
we do this by calling our X dot
- 0:57
observable create and then create takes
- 1:00
a observer function where we can define
- 1:02
what the observable sends to the
- 1:04
subscriber to send values you call
- 1:07
observer next with the value you want to
- 1:09
send and that value can be anything it
- 1:10
could be a string and object or whatever
- 1:12
you want then to make the observable
- 1:15
start emitting values you call subscribe
- 1:17
on it in this case we'll take each value
- 1:18
and just print it to the screen if we
- 1:21
refresh our page you can see we get
- 1:23
hello world print it to the screen so
- 1:25
that's pretty cool but we don't normally
- 1:27
need to create observables manually like
- 1:29
this let's say we wanted to create an
- 1:31
observable from click events in the Dom
- 1:33
we can call observable from event pass
- 1:36
at the document and the event we want to
- 1:38
observe in this case clicks so just like
- 1:40
before we subscribe to it but at this
- 1:42
time we'll console.log it just to show
- 1:43
the full event object each time we click
- 1:45
the page we get the mouse event logged
- 1:47
along with all of its associated data if
- 1:50
you work with asynchronous JavaScript
- 1:51
you're probably used to working with
- 1:52
promises and we can convert a promise
- 1:55
directly into an observable so here
- 1:57
we're just creating a promise with a
- 1:59
timeout that resolves after one second


