Chapter 6. FRP on the web

 

This chapter covers

  • Observables in RxJS
  • How to manage state in RxJS
  • RxJS examples
  • A glimpse of Kefir.js and Flapjax
  • Glitches/inconsistent handling of simultaneous events

FRP fits some problems better than others. User interfaces and networking are two event-based areas where it fits especially well. Not surprisingly, FRP is excellent for web applications.

RxJS—part of the Reactive Extensions suite—is a system widely used in web applications that has an FRP capability. In this chapter, we show how to use it for FRP by contrasting it against Sodium, which we’re treating as a model of true FRP.

Note

Appendix C contains comparison charts for all the systems discussed here.

6.1. RxJS

Reactive Extensions started as a library from Microsoft for the .NET platform, known for short as Rx.NET. It has now been translated into almost every language, and the JavaScript version is called RxJS.

There are many other JavaScript systems inspired by RxJS, including Bacon.js, Kefir.js, and Meteor Tracker. Flapjax is another JavaScript system from the same “classic FRP” lineage that Sodium comes from. We’ll compare one example among three systems: RxJS, Kefir.js, and Flapjax.

The goals and design philosophy of Rx are a little different than Sodium’s:

6.2. Observable

6.3. Keeping state in RxJS, Kefir.js, and Flapjax

6.4. The latest of two observables with combineLatest

6.5. Creating your own hot observable

6.6. Example: autocomplete the FRP way

6.7. RxJS/Sodium cheat sheet

6.8. Static typing preferred

6.9. Summary