All Projects → mikesol → plzwrk

mikesol / plzwrk

Licence: BSD-3-Clause license
A Haskell front-end framework

Programming Languages

haskell
3896 projects
Dockerfile
14818 projects

Labels

Projects that are alternatives of or similar to plzwrk

fa.BlackIQ.ir
Persion version of BlackIQ.ir
Stars: ✭ 16 (-52.94%)
Mutual labels:  front-end
ng-thingsboard
Angular 8 Thingsboard UI
Stars: ✭ 27 (-20.59%)
Mutual labels:  front-end
tags
HTML tags in Go
Stars: ✭ 50 (+47.06%)
Mutual labels:  front-end
BlackIQ.ir
BlackIQ.ir Source Code
Stars: ✭ 14 (-58.82%)
Mutual labels:  front-end
ustyle
A living styleguide and pattern library by uSwitch.
Stars: ✭ 18 (-47.06%)
Mutual labels:  front-end
yhtml5-tutorial
the tutorial for learning Front-end technology
Stars: ✭ 19 (-44.12%)
Mutual labels:  front-end
meshery.io
Site for Meshery, the cloud native management plane
Stars: ✭ 135 (+297.06%)
Mutual labels:  front-end
hocus-focus
A keyboard navigation horror game.
Stars: ✭ 70 (+105.88%)
Mutual labels:  front-end
buttono
A flexible Sass mixin for creating BEM-style buttons.
Stars: ✭ 82 (+141.18%)
Mutual labels:  front-end
jigjs
🧩 A front-end framework
Stars: ✭ 22 (-35.29%)
Mutual labels:  front-end
invoiced-ui
Example project for the React Foundation Series
Stars: ✭ 26 (-23.53%)
Mutual labels:  front-end
front-end-challenge
Desafio para candidatos a front-end.
Stars: ✭ 170 (+400%)
Mutual labels:  front-end
ui-engineering-questions
Questions for UI engineers and front-end developers
Stars: ✭ 13 (-61.76%)
Mutual labels:  front-end
ninjajs
Micro and elegant frontend framework
Stars: ✭ 14 (-58.82%)
Mutual labels:  front-end
front-end-responsibilities
A laundry list of possible front-end engineering responsibilities
Stars: ✭ 39 (+14.71%)
Mutual labels:  front-end
silverplate
🌐 Front-end boilerplate with Webpack, Hot Reload, Tree-Shaking and React
Stars: ✭ 64 (+88.24%)
Mutual labels:  front-end
Emory-BMI-GSoC
Emory BMI GSoC Project Ideas
Stars: ✭ 27 (-20.59%)
Mutual labels:  front-end
react-native-single-select
Customizable & Easy to Use Single Select Library for React Native
Stars: ✭ 74 (+117.65%)
Mutual labels:  front-end
react-native-header-search-bar
Fully customizable header search bar for React Native
Stars: ✭ 101 (+197.06%)
Mutual labels:  front-end
py-emmet
Emmet abbreviation parser and expander, implemented in Python
Stars: ✭ 32 (-5.88%)
Mutual labels:  front-end

plzwrk

Chat on Gitter

A Haskell front-end framework.

Available as a Hackage package: plzwrk

📖 Looking for an overview? Read our announcement blog post.

In this document:

When to use plzwrk

plzwrk may be a good fit if you enjoy the benefits of programming in Haskell and you'd like to create a web app.

⚠️ Warning: plzwrk is experimental. It is unfit for production and the syntax will change frequently, often in non-backward-compatible ways. We will try to document all of these changes in the changelog.

Some alternatives to plzwrk:

  • Elm, a delightful language for reliable web apps.
  • Purescript react basic, an opinionated set of bindings to the React library, optimizing for the most basic use cases.

Examples using plzwrk

Hello world

An example web page that says 'Hello world!'

{-# LANGUAGE QuasiQuotes #-}

import Web.Framework.Plzwrk
import Web.Framework.Plzwrk.Asterius

main :: IO ()
main = do
  browser <- asteriusBrowser
  plzwrk'_ [pwx|<p>Hello world!</p>|] browser

See the Hello World example live.

Aphorism machine

An Aphorism Machine that spits out and hides universal truths on demand.

Check out the source code in the kitchen-sink directory. Or see the Aphorism Machine live.

Making a webpage

plzwrk uses Asterius as its backend for web development.

A minimal flow is shown below. It assumes that you have a file called Main.hs in the present working directory with a function main :: IO () inside of it, not unlike in our hello world example.

username@hostname:~/my-dir$ docker run --rm -it -v $(pwd):/project -w /project meeshkan/plzwrk
asterius@hostname:/project$ ahc-link --input-hs Main.hs --browser --bundle

If you're using ahc-cabal, compiling an application using plzwrk is no different than compiling an application as described in the Asterius documentation with one caveat. You must use --constraint "plzwrk +plzwrk-enable-asterius" when running ahc-cabal.

Documentation

The main documentation for plzwrk is on Hackage.

The four importable modules are:

Design of plzwrk

plzwrk is inspired by Redux for its state management. The main idea is that you have an HTML-creation function that is composed, via <*>, with getters from a state.

-- State
data MyState = MkMyState { _name :: Text, age :: Int, _tags :: [Text] }

-- Function hydrating a DOM with elementse from the state
makeP = (\name age ->
  [pwx'|<p>#t{concat [name, " is the name and ", show age, " is my age."]}#</p>|])
    <$> _name
    <*> _age

-- The same function using functional tags instead of pwx
makeP = (\name age ->
    p'__ concat [name, " is the name and ", show age, " is my age."])
      <$> _name
      <*> _age

HTML-creation functions can be nested, allowing for powerful abstractions:

nested = div_ (take 10 $ repeat makeP)

PWX

pwx is similar to jsx. The main difference is that instead of only using {}, pwx uses four different varieties of #{}#:

  • #e{}# for a single element.
  • #el{}# for a list of elements.
  • #t{}# for a single piece of text, either as a node in the body of an element or as a text attribute.
  • #c{}# for a callback attribute.

Hydrating with a state

HTML-creation functions use an apostrophe after the tag name (ie div') if they accept arguments from a state and no apostrophe (ie div) if they don't. The same is true of pwx, ie [pwx|<br />|] versus (s -> [pwx'|<br />|]).

Additionally, HTML-creation functions for tags that don't have any attributes (class, style, etc) are marked with a trailing underscore (ie div_ [p__ "hello"]), and tags that only accept text are marked with two trailing underscores (ie p__ "hello").

Event handlers

Event handlers take two arguments - an opaque pointer to the event and the current state. Then, it returns a new state (which could also be the original state) in the IO monad.

For example, if the state is an integer, a valid event handler could be:

eh :: opq -> Int -> IO Int
eh _ i = pure $ i + 1
dom = [pwx|<button click=#c{eh}#>Click here</button>|]

To handle events, you can use one of the functions exported by Web.Framework.Plzwrk. This could be useful to extract values from input events, for instance. Please see the Hackage documentation for more information.

Server-side rendering

plzwrk supports server-side rendering. To do this, you have to compile your site twice:

When compiling using ahc-cabal, make sure to use the plzwrkSSR family of functions. These functions will look for pre-existing elements in the DOM and attach event listeners to them instead of creating elements from scratch.

There may also be times that the static website needs to be initialized with data (ie using the result of an HTTP response made on the server). In this case, you'll need to pass these values dynamically to the function that calls plzwrkSSR. You can do this using the foreign export syntax as described in the Asterius documentation.

When compiling with cabal, you'll likely be using it to output an HTML document or build a server that serves your website as text/html. Regardless of the approach, you should use toHTML to create the part of the initial DOM controlled by plzwrk. In your HTML, make sure to include a link to the script(s) produced by ahc-dist. Also, if needed, make sure to call your exported functions.

Testing your code

plzwrk comes with a mock browser that can act as a drop-in replacement for your browser.

You can use this in your tests:

import Web.Framework.Plzwrk.MockJSVal

main :: IO ()
    browser <- makeMockBrowser
    print "Now I'm using the mock browser."

Contributing

Thanks for your interest in contributing! If you have a bug or feature request, please file an issue. Or if you'd like to hack at the code base, open a pull request.

Please note that this project is governed by the Meeshkan Community Code of Conduct. By participating, you agree to abide by its terms.

Local development

  1. Clone this repository: git clone https://github.com/meeshkan/plzwrk.git
  2. Move into the directory: cd plzwrk
  3. Set up your local environment: You can use this guide from The Haskell Tool Stack for reference.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].