Code Monkey home page Code Monkey logo

rxplay's Introduction

Download the full project report in PDF.

RxPlay : Observables for Play !

We demonstrate here how we can efficiently use RxScala to write reactive apps in Play framework. This comes from the observation that Iteratees from Play may be harder to work with than Observables from Rx.

First, we have to deal with the problem that Play uses Iteratees, Enumeratees and Enumerators to handle data reactively. Iteratee is the consumer, Enumeratee the transformer and Enumerator the producer. In Rx, the Observable object has the three roles. Thanks to the work from Bryan Gilbert, we have an implicit mapping between Enumerators and Observables, that we can store in RxPlay.scala library.

Then, we see that Iteratees and Enumerators are deeply integrated with the Play framework. Our ultimate goal would be to make them completely disappear from the coder side. This project will illustrate how it can be done in a specific example : WebSockets. Indeed, to deal with them in Play you have to return an Iteratee (data consumer) and an Enumerator (data producer) to respectively handle data received from the client side and send them data. If you need to modify the data you send depending (which is often the case), you need complicated dependency between the two objects. If we can work with Observables in that case, this leads to an easier way to code, but with the problem that we cannot respect the Play API. We need to return (in: Iteratee, out: Enumerator). This is what I will now call a WebSocket and what the WidgetManager class will handle to bridge our simple Observables to that structure.

This repo contains the following Play projects

  • RxTime : the simplest possible app that could serve as a template project. This is a simple web page with a single button. When you click on it, this creates an Observable on the server that will produce the time every second. You can stop the clock (i. e. unsubscribe from the Observable) and start it again (new subscription).

  • RxTwitterStats : this is a complex app illustrating the power of RxPlay combined with WidgetManager (several Observables, chaining them, buffering, etc). This will show real-time tweets for a specific keyword. Top 3 mentionned users and number of tweets per second are displayed on screen. See Readme from the project directory for details and configuration (to add your Twitter tokens).

the necessary files

  • WidgetManager files : this directory contains the three only files that you will need in order to add the WidgetManager to any existing Play application. Just add the JavaScript file to your resources folder and the scala files to your app/ folder. After importing the Scala objects in your server side application and the JS one in the HTML file you will be able to create reactive apps using WidgetManager that is transparently handling WebSockets for you.

other libraries

  • CometObs.scala : this class is the conversion of the Comet class from Play to make it work with Observables instead of Iteratees.

Project by François Farquet, June 2014, EPFL.

rxplay's People

Contributors

farquet avatar

Watchers

James Cloos avatar Vadim Bondarev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.