This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Map Streams to Values to Affect State

    John LindquistJohn Lindquist

    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.

    angularAngular
    2 - 6
    rxjsRxJS
    5 - 6
    ngrx-store@ngrx/store
    Code

    Code

    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
    Transcript

    Transcript

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

    00:09 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.

    00:28 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.

    00:41 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.

    01:08 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.

    Discuss

    Discuss