• Stars
    star
    566
  • Rank 78,774 (Top 2 %)
  • Language PureScript
  • License
    Other
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build type-safe web apps with PureScript.

PUX

Build type-safe web applications with PureScript.

Documentation | Examples | Chat

Latest Release ComVer Build Status Gitter Chat

Pux is a PureScript library for building web applications. Interactive UI is modeled as a single state transition function, Event -> State -> (State, HTML) which is run for every event. Pux also provides tooling such as:

  • Isomorphic routing and rendering
  • Hot reloading
  • Render to React (or any virtual DOM library)
  • Time-travelling debug extension

Quick start

The starter app provides everything you need to get started:

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

Example

The following chunk of code sets up a basic counter that can be incremented and decremented:

module Main where

import Prelude hiding (div)
import Control.Monad.Eff (Eff)
import Pux (CoreEffects, EffModel, start)
import Pux.DOM.Events (onClick)
import Pux.DOM.HTML (HTML)
import Pux.Renderer.React (renderToDOM)
import Text.Smolder.HTML (button, div, span)
import Text.Smolder.Markup (text, (#!))

data Event = Increment | Decrement

type State = Int

-- | Return a new state (and effects) from each event
foldp :: ∀ fx. Event -> State -> EffModel State Event fx
foldp Increment n = { state: n + 1, effects: [] }
foldp Decrement n = { state: n - 1, effects: [] }

-- | Return markup from the state
view :: State -> HTML Event
view count =
  div do
    button #! onClick (const Increment) $ text "Increment"
    span $ text (show count)
    button #! onClick (const Decrement) $ text "Decrement"

-- | Start and render the app
main :: ∀ fx. Eff (CoreEffects fx) Unit
main = do
  app <- start
    { initialState: 0
    , view
    , foldp
    , inputs: []
    }

  renderToDOM "#app" app.markup app.input

Benchmarks

Table of benchmarks comparing rendering speed of similar libraries

Why is Pux slow?

Pux has not focused on performance yet. The slow performance arises from translating Pux's (smolder) virtual DOM to React's virtual DOM. The goal is to write a purescript virtual DOM module for smolder, which would avoid that translation step and could be optimized for a monadic datastructure. I suspect this would achieve performance on par with Halogen.

Below are the render steps for the other libraries compared, which shows that Pux is the only one that has an intermediate virtual DOM representation (it has to render to React first then React has to render):

  • Elm = Virtual DOM -> DOM patch
  • React = Virtual DOM -> DOM patch
  • Thermite = Virtual DOM -> DOM patch
  • Halogen = Virtual DOM -> DOM patch
  • Pux = Smolder Markup -> React Virtual DOM -> DOM patch

More Repositories

1

sticky

Simple, key/value pair browser-storage cache leveraging the latest HTML5 storage APIs.
JavaScript
324
star
2

jsx-transform

JSX transpiler. A standard and configurable implementation of JSX decoupled from React.
JavaScript
293
star
3

koa-resource-router

RESTful rails-style resource routing for koa
JavaScript
147
star
4

pux-starter-app

Starter Pux app w/ hot-reloading and isomorphic routing and rendering
PureScript
102
star
5

twain

Tiny web application framework for WAI.
Haskell
66
star
6

pux-devtool

Pux time-travelling devtool.
JavaScript
43
star
7

gulp-file

Create vinyl files from a string or buffer and insert into the Gulp pipeline.
JavaScript
42
star
8

mongoose-populate-virtuals

Extend Mongoose 4+ population with virtual attributes that can be populated in either direction.
JavaScript
33
star
9

virtual-dom-component

A virtual component (view). Virtual components expose events, state lens, and a render function.
JavaScript
30
star
10

virtual-dom-stringify

Deprecated. Use https://github.com/nthtran/vdom-to-html/.
JavaScript
25
star
11

html-virtualize

Parse HTML into virtual-dom tree.
JavaScript
20
star
12

gulp-jsx

virtual-dom-jsx for gulp
JavaScript
14
star
13

pux-todomvc

Pux TodoMVC
PureScript
13
star
14

express-elasticsearch-logger

Log requests to ElasticSearch.
JavaScript
12
star
15

modella-resource

Expose Modella models via RESTful resource middleware.
JavaScript
10
star
16

watch

Watch files and folders for changes, and run commands when they change. Linux, OS X, and Windows are supported.
Go
8
star
17

hyperobject

A simple object model for working with Linked Data.
JavaScript
7
star
18

dotfiles

My OS X setup using Nu shell and Helix editor.
Nushell
7
star
19

pux-css

Render purescript-css to a Pux attribute.
PureScript
5
star
20

modella-mysql

MySQL plugin for Modella.
JavaScript
4
star
21

mongoose-express-router

Create Express 4 router and middleware from Mongoose 4 model.
JavaScript
4
star
22

charisi

A rich text editor for the web, built for speed and stability
JavaScript
3
star
23

purescript-markdown-smolder

Render purescript-markdown to purescript-smolder.
PureScript
3
star
24

webmention

Types and functions for working with webmentions.
Haskell
3
star
25

pux-websockets

PureScript
3
star
26

wai-responder

A tiny web application framework for WAI.
Haskell
2
star
27

modella-memory

Memory persistence layer for Modella. Useful for development or as a reference implementation for Modella storage plugins.
JavaScript
2
star
28

express-snapshot

Generate static HTML from Express. Express app in, static .html out.
JavaScript
2
star
29

zero.css

Classy style without classes
CSS
1
star
30

daily-standup

Command-line tool for posting what you did today and the GitHub commits from yesterday to HipChat.
JavaScript
1
star