Git Product home page Git Product logo

node-reactive-clicker's Introduction

Button clicker

A clicker button, that streams!

clicker screenshot

Introduction

Using Server Sent Events (SSE), vanilla javascript and an express server, I created a simple app, where a user clicks a button and streams it through SSE.

Basically every time you click the button on the main page (/), its value is incremented by 1. This event is then sent to the server for eventual propagation. Using an EventEmitter N listeners can subscribe to this unique session and reacting to it. When opening a subscription window, the button value should evolve together with the main page.

What's magical here (at least for me), is the use of basic HTTP headers to create a keep-alive session that allow SSEs. The same goes for the clientside javascript, only using EventSource it's possible to create a reactive client-side app without all the burder of websockets!

This project is born from multiple sources of inspiration. First a fantastic talk I saw at MiXiT Lyon in 2017 by Audrey Neuveu (in French). Then, my desire to learn more about raw HTTP and its brilliant headers. Thirdly, a great article explaining how to do SSEs in nodejs by Tom Kernsten. And finally, just the fun of making a "reactive" app out of nearly bare nodejs.

Pages

/

The main page, where a session is started, to register the click.

/view/:sessionid

The "tv" page, where one can follow the activity of a precise session

REST endpoints

GET /session

Create a new session and returns it.

GET /sessions/:id

Retrieves the current state of the session

PUT /sessions/:id/click

Increment the clicks value of the session by one.

GET /sessions/:id/stream

Open the SSE session.

node-reactive-clicker's People

Contributors

jquagliatini avatar

Watchers

James Cloos avatar  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.