Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Extend Subscriber to Override `_next` in RxJS


    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.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: 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.

    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.

    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.

    This destination is simply this subscriber. This double subscriber is wrapping that subscriber and transforming that value before it passes it on.