Extend Subscriber to Override `_next` in RxJS

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

The Subscriber class exposes a _next method which you can override to handle how the destination's next function will be called. This allows you to create your own variations of the Subscriber class to intercept what happens between the observable and the destination subscriber.

Instructor: [00:00] Import subscriber. Then this is a class which we can extend. I'll call this double subscriber. Extends subscriber. Then I'm simply going to implement an _next function, which takes a value and then with that value calls this destination, next. I'm going to pass in that value times two.

[00:27] With this double subscriber, which is not being used yet, I'm going to subscribe to a new instance of the double subscriber and pass in our subscriber from above.

[00:42] You can see up here that the values are now 2, 4, 6, 8, 10. The values coming into here, if I just log these out, are one, two, three, four, five. Then they get doubled and passed down to this subscriber.

[00:56] This destination is simply this subscriber. This double subscriber is wrapping that subscriber and transforming that value before it passes it on.

Alexander
Alexander
~ a year ago

where did destination property come from? is it something built in to javascript?

Lucas Minter
Lucas Minter
~ a year ago

where did destination property come from? is it something built in to javascript?

Here is an article I found on RxJs Observables. destination looks like it's an RxJS feature. https://medium.com/swlh/observables-angular-7e11ad612072

Markdown supported.
Become a member to join the discussionEnroll Today