Coder Social home page Coder Social logo

puxws's Introduction

puxws

Standalone example of purescript-pux using purescript-websocket-simple

What's here

Simple variation on the purescript-pux Affjax example with an integration of websockets in a similar manner.

Basic approach

I've put the websocket connection handler into the State of the Pux application, so that the forall e. Eff ( ws :: WEBSOCKET | e) can be available inside the update function that is handling the Actions.

Then, in the main, i make a channel for the type of action that is going to be sent in response to data received on the websocket. That channel is used in the construction of the inital state, setting up the onmessage for the websocket to send a ReceiveWSData action in that channel.

Next i subscribe a Signal to this Channel and i use that Signal in the config of the Pux app.

Upshot of this is that the rightmost button, marked "Socket", when clicked generates an Action ButtonFour which in turn sends a message on a websocket to ws://echo.websocket.org from whence it echoes back, causing a new Action ReceiveWSData which simply puts the received string into the DOM (State.banner) so that we can see it.

puxws's People

Contributors

afcondon avatar

Watchers

 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.