Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

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


    Logging a Stream with Do


    To help understand your stream, you’ll almost always want to log out some the intermediate values to see how it has progressed during its lifespan. This lesson teaches you how to use do to log values in the middle of the stream without having an impact on the rest of the stream.



    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




    The way this is currently set up, we only see the final output once we've hit complete, and we've reduced the final score into something that gets pushed through to the onNext. I also want to see what's going on during my streams. An easy way to do that is to drop in a do operator. The do allows you to do a side effect, so something that's going to happen outside of our stream.

    We'll go ahead and console.log this data which is being pushed through, which will be this formatted timer and input object. Now when I type zero, you can see I get the count zero and the text "zero." When I hit start, you can see I get one. I'll type one, two, four, so I missed one. My final score was two. You can see that it completed.

    You can go back through and see four didn't match a text of nothing, three didn't match a text of nothing, and that my points came from one and an initial zero. You can see what happened in the stream as it went along. You can ahead and put these dos anywhere.

    If I cut this, and paste it here, and paste one here, and I hit Save, you can see we now get that initial count of zero, which we didn't get until we typed a four. I can type something, just get the letter a. I can hit start, get my objects I used to get, and type, and get that typing. Then it still counts the score and completes as expected.

    These don't affect anything inside of our stream. They happen completely outside of what's going on.