Basic DOM Rendering with Subscribe

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 5 years ago

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.

[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.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today