Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.82 KB

listen.md

File metadata and controls

42 lines (30 loc) · 1.82 KB
id lesson title layout class preview_image preview_image_alt
listen
3
Learn reactive programming - Lesson 3, Reactivity
default
post
listen/content_preview.jpg
Subscribe reactive method and listeners

So far you learned 2 essential Reactive Programming principles: streams and immutability. Today we explore a third principle: reactivity. You'll need:

  • a new ❚ subscribe card
  • a new ▬ setWifi listener piece

{:.w100}

The ▬ setWifi listener piece. It turns the wifi on or off.

You also need all the cards and pieces you previously received. Let's put them all together like this:

{% include card_player.html video=238900495 episode=true %}

Chain

Yes! You can put cards one after another, in a chain. Each card in this chain operates on the stream generated by the previous card:

  • ❚ fromEvent reacts to the ▬ toggle. It creates a sequence of toggle events over time, in reaction to each toggle status change (read Episode 1).
  • ❚ map projects each toggle events to ✔ true or ✘ false (read Episode 2).
  • ❚ subscribe adds ▬ setWifi as a listener of the stream. This listener accepts boolean values (✔ true or ✘ false) and turns the wifi on or off accordingly.

Summary

In Reactive Programming we react to piece and stream updates. This is the reactivity principle. And today, by assembling several cards together, you built your first reactive machine!

  • you unlocked ❚ subscribe
  • you unlocked ▬ setWifi
  • you created a chain of cards
  • you subscribed to a stream, adding a listener
  • you learned the principle of reactivity

You now have the basic knowledge of Reactive Programming. Over the next lessons, you'll receive new cards that transform streams.