Book Image

Reactive Programming with JavaScript

By : Jonathan Hayward
Book Image

Reactive Programming with JavaScript

By: Jonathan Hayward

Overview of this book

<p>Reactive programming is carried out using the building blocks of functional programming. JavaScript libraries such as ReactJS are used for front-end web development that is both competent and powerful. ReactJS is intensively being used to develop webapps for Facebook.</p> <p>This title is among the first of those addressing how everyday programmers can take advantage of reactive programming without having an extremely heavy mathematical background. It starts with the basics a front-end developer can easily connect with, while also covering the basics of functional programming. Then it goes on to explain non-functional reactive programming with the help of a live example. After that it gives a theoretical overview of reactive programming supported by functional programming. Tools to make functional programming easier like Bacon.js, a library like jQuery, are also covered. Finally, it finishes with building one small and one larger front-end project.</p>
Table of Contents (20 chapters)
Reactive Programming with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Demonstrating Functional Reactive Programming in JavaScript with a Live Example Part II – A To-do List
Index

This project's first complete component


You can see what this component implements at https://CJSHayward.com/missing.html. For our first component, we pick a mostly skeletal implementation:

  var YouPick = React.createClass({
    getDefaultProps: function() {
      return null;
    },
    getInitialState: function() {
      return null;
    },
    render: function() {
      return <div />;
    }
  });

This skeleton returns empty, "falsy" values, which we will override. What we want to do is take two strings, break them down into one-character substrings (excluding tags), then display more and more of the first string, and then repeat the second string. It makes for a very old joke displayed for the user.

There is a division of labor between properties, meant to be set once and never changed and state, meant to allow changing. Note that state, being mutable, should be treated privately, so as to avoid the shared mutable state that Facebook declared war on. Technically, properties can be...