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

    Basic DOM Rendering with Subscribe

    John LindquistJohn Lindquist

    While frameworks like Angular 2 and CycleJS provides great ways to update the DOM and handle subscriptions for you, this lesson shows how you can still do basic subscribe blocks and manually update the DOM on your own.

    rxjsRxJS
    ^5.0.0
    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 Frameworks that can render out streams like Angular2 and Cycle.js will subscribe to these streams for you inside of either the Angular2 template or using dom drivers in Cycle.js. You just write a lot of streams and let them handle the subscriptions for you.

    00:16 Since we're taking a raw approach, we have to write our rendering inside of our subscribe blocks because these are the side effects of the output of our streams. Instead of just logging out the score, let's go ahead and set up a div that says score with a span ID of score so we can grab that here. Say document query selector with an ID of score. We'll set the inner html to a template string, and then just render out that value of x inside of our stream.

    00:48 Now, when I save and I start my game, I'll go one, two, three. You can see I got a score of two. I can try again. One, two, three. Got a score of zero that time. That way we have a fully working game that you could share with anyone.

    Discuss

    Discuss