ryoia / purescript-pux

A PureScript FRP interface to React.

Home Page:http://alexmingoia.github.io/purescript-pux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pux

Latest release Build Status Gitter Chat

Pux is an FRP interface to React, based on the Elm app architecture. It is a simple pattern for modular, nested components that are easy to test, refactor, and debug - making it simple and straightfoward to build complex web applications.

  • Build React UIs as a fold of actions to state via purescript-signal
  • Type-safe routing
  • Server-side rendering (isomorphic applications)
  • Hot-reloading of components
  • Easy interop with existing React components

Installation

The easiest way to get started is to clone the starter app, which includes a hot-reloading setup using webpack:

git clone git://github.com/alexmingoia/pux-starter-app.git example
cd example
npm install
npm start

Pux is also available as the bower package purescript-pux.

Example

The following chunk of code sets up a basic counter that you can increment and decrement:

import Prelude (Unit, bind, const, show, (++), (-), (+))

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Signal.Channel (CHANNEL)

import Pux (renderToDOM, fromSimple, start)
import Pux.Html (Html, text, button, span, div)
import Pux.Html.Events (onClick)

data Action = Increment | Decrement

type State = Int

update :: Action -> State -> State
update Increment count = count + 1
update Decrement count = count - 1

view :: State -> Html Action
view count =
  div
    []
    [ button [ onClick (const Increment) ] [ text "Increment" ]
    , span [] [ text (show count) ]
    , button [ onClick (const Decrement) ] [ text "Decrement" ]
    ]

main :: forall e. Eff (err :: EXCEPTION, channel :: CHANNEL | e) Unit
main = do
  app <- start
    { initialState: 0
    , update: fromSimple update
    , view: view
    , inputs: []
    }

  renderToDOM "#app" app.html

About

A PureScript FRP interface to React.

http://alexmingoia.github.io/purescript-pux

License:Other


Languages

Language:PureScript 91.6%Language:JavaScript 8.4%