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.


    Map Streams to Values to Affect State

    John LindquistJohn Lindquist
    2 - 6
    5 - 6

    While you have multiple streams flowing into your scan operator, you'll need to map each stream to the specific values you need to update your state the way that you want. This lesson covers using the map operator to determine what the click and interval should do when the state is updated.



    Become a Member to view code

    You must be a 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




    Now to change the behavior so that when this pushes through, it only updates one second, and when this pushes through, it'll update an entire hour.

    What we have to do is use something like map two, and we're going to send along a string of second. I'll say map two and we'll send along a string of hour. I need to go ahead and import map two.

    Now, what comes through in this current is either second or hour, because those are the things being pushed through in this merged observable, either hour or second will come through into my scan function.

    I can go ahead and check, and see if the current is second. If it is, we'll just go ahead and update the seconds. Or if the current is equal to hour, let's go ahead and copy this, paste it, and change seconds to hours and change seconds to hours.

    Now when I hit save and I refresh, you can see the time keeps ticking along, one second per time, because second is coming through and it's hitting this if block. But if I click update, it's updating the hours, so I can move the time much faster, because it's sending the word "hour" through. It hits this if block and it sets the hours on the date to plus one and then returns the date.