Git Product home page Git Product logo

purescript-pux's Introduction

Pux

ComVer Build Status NPM Version Bower Version Gitter Chat

Pux is a PureScript interface to React, similar to 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 straightforward to build complex web applications.

  • Build React UIs as a fold of actions to state.
  • Type-safe routing
  • Server-side rendering (isomorphic applications)
  • Hot-reloading of components
  • 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

purescript-pux's People

Contributors

alexmingoia avatar charleso avatar chexxor avatar damncabbage avatar eskimor avatar garyb avatar jdanford avatar jgoux avatar justinwoo avatar kritzcreek avatar kurtharriger avatar megamaddu avatar menelaos avatar michaelxavier avatar mostalive avatar mrmurphy avatar omerzach avatar parsonsmatt avatar passy avatar prikhi avatar puffnfresh avatar ryoia avatar simonyangme avatar thimoteus avatar werehamster avatar

Watchers

 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.