So far you learned 2 essential Reactive Programming principles: streams and immutability. Today we explore a third principle: reactivity. You’ll need:
❚ subscribe
card▬ setWifi
listener pieceThe
▬ 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:
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.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!
❚ subscribe
▬ setWifi
You now have the basic knowledge of Reactive Programming. Over the next lessons, you’ll receive new cards that transform streams.
Freelance Developer Advocate. Motion graphics with code. JavaScript and Elm. cedricsoulas.com
Receive my latest news, product updates and programming visualizations. You can unsubscribe at any time.