• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language PureScript
  • Created about 6 years ago
  • Updated over 4 years ago

Reviews

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

Repository Details

Hedwig is a fast, type safe, declarative PureScript library for building web applications.

Hedwig

Hedwig is a fast, type safe, declarative PureScript library for building web applications.

Getting Started | Examples

Features

Fast

The performance of Hedwig is competitive with mainstream JavaScript frameworks, both in terms of CPU usage and Memory consumption. In js-framework-benchmark, Hedwig performs as well as or better than React, Angular, and Vue.

Small

A Hello World program weighs in at around 11kB minified + gzipped. The js-framework-benchmark implementation weighs in at around 16kB.

Declarative Animations

Animations are essential to maintain a direct and engaging real-world feel. Hedwig makes adding animations easy using a declarative CSS transition based API. Read More ↓

Integration with Developer Tools

Hedwig integrates with Redux DevTools to provide an interactive state modification viewer and time travelling debugger. Read More ↓

Getting Started

You'll need to have Node.js and pulp installed.

You can either clone the starter template or follow the instructions below to create an application from scratch.

Starter Template

Clone the repository, install the dependencies, and start the dev server:

$ git clone https://github.com/utkarshkukreti/purescript-hedwig-starter my-app
$ cd my-app
$ npm install
$ bower install
$ npm start

and open index.html in your browser.

From Scratch

Initialize a new project using pulp and create an empty package.json:

$ mkdir my-app
$ cd my-app
$ pulp init
$ echo '{}' > package.json

Install the dependencies:

$ bower install --save purescript-hedwig
$ npm install --save purescript-hedwig

Create an HTML file to load the JS (save this to index.html):

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My App</title>
  </head>
  <body>
    <main></main>
    <script src="index.js"></script>
  </body>
</html>

Create and mount the application (save this to src/Main.purs):

module Main where

import Prelude

import Effect (Effect)
import Hedwig as H
import Hedwig ((:>))

type Model = Int

init :: Model
init = 0

data Msg = Increment | Decrement

update :: Model -> Msg -> Model
update model = case _ of
  Increment -> model + 1
  Decrement -> model - 1

view :: Model -> H.Html Msg
view model = H.main [H.id "main"] [
  H.button [H.onClick Decrement] [H.text "-"],
  H.text (show model),
  H.button [H.onClick Increment] [H.text "+"]
]

main :: Effect Unit
main = do
  H.mount "main" {
    init: init :> [],
    update: \msg model -> update msg model :> [],
    view
  }

Compile the application:

$ pulp browserify --to index.js

Finally, open index.html in your browser. You should now see the text "Hello, world!" appear on the screen.

Animations

Hedwig provides two main functions to add animation to elements:

Hedwig Declarative Animations

(1) Hedwig.transition :: String -> Trait msg

Adding this to the traits list of an element will make Hedwig to add 6 classes to the element at different times. The String argument is the prefix to use for the classes. Let's say we do div [Hedwig.transition "fade"] [text "Hello"] . This will apply 6 classes:

  1. fade-enter: Starting state for enter. Added before element is inserted, removed one frame after element is inserted.

  2. fade-enter-active: Active state for enter. Applied during the entire entering phase. Added before element is inserted, removed when transition/animation finishes. This class can be used to define the duration, delay and easing curve for the entering transition.

  3. fade-enter-to: Ending state for enter. Added one frame after element is inserted (at the same time v-enter is removed), removed when transition/animation finishes.

  4. fade-leave: Starting state for leave. Added immediately when a leaving transition is triggered, removed after one frame.

  5. fade-leave-active: Active state for leave. Applied during the entire leaving phase. Added immediately when leave transition is triggered, removed when the transition/animation finishes. This class can be used to define the duration, delay and easing curve for the leaving transition.

  6. fade-leave-to: Ending state for leave. Added one frame after a leaving transition is triggered (at the same time v-leave is removed), removed when the transition/animation finishes.

Inspiration for the feature and source of the description above..

With a tiny bit of CSS, you can create all sorts of animations with the above. See the AnimatedList.purs and AnimatedList.css and its Live Demo for an example.

Hedwig.transition' is similar but lets you specify custom class names to add for each stage.

  1. Hedwig.transitionGroup :: String -> Trait msg

A transition group enables normal transition on all its children elements, plus it keeps track of the positions of its children, and whenever that changes, adds CSS classes and a CSS transform to them. With a line of CSS, you can animate the movement of the nodes:

.fade-move {
  transition: transform 0.2s;
}

See AnimatedList.purs and AnimatedList.css and its Live Demo for an example.

Hedwig.transitionGroup' is similar but lets you specify custom class names to add for each stage.

Developer Tools

Hedwig integrates with Redux DevTools to provide an interactive state modification viewer and time travelling debugger.

Hedwig with Redux DevTools

(To try this right now, install the Redux DevTools Chrome Extension and head over to this page.)

To enable this, you need to do two things:

  1. Import Hedwig.Devtools

  2. In your main function, before you mount the application, call Hedwig.Devtools.init.

For an example, check out the source of the Counters example.

After recompiling your application, you should see all messages and state being logged into the Redux tab of Chrome DevTools window.

Examples

The examples/ directory contains a bunch of examples:

  • HelloWorld (Demo) - Just writes the text "Hello, world!" to the screen.

  • Counter (Demo) - A numeric counter with increment and decrement buttons.

  • Counters (Demo) - A dynamic list of numeric counters.

  • Dice (Demo) - Rolls a dice using the purescript-random package. Showcases how a Hedwig application can run side effects.

  • Prompt (Demo) - Prompts the user to enter their name by calling window.prompt. Also showcases how to run functions with side effects.

  • AnimatedList (Demo) - An animated list of boxes.

  • JsFrameworkBenchmark (Demo) - An implementation of js-framework-benchmark. See benchmark results here.

More Repositories

1

select.rs

A Rust library to extract useful data from HTML documents, suitable for web scraping.
Rust
953
star
2

markup.rs

A blazing fast, type-safe template engine for Rust.
Rust
350
star
3

draco

Draco is a Rust library for building client side web applications with Web Assembly.
Rust
301
star
4

ex_top

ExTop is an interactive monitor for the Erlang VM written in Elixir.
Elixir
292
star
5

speculate.rs

An RSpec inspired minimal testing framework for Rust.
Rust
270
star
6

reaml

A React binding for (OCaml | ReasonML) + BuckleScript with compile time enforcement of the "Rules of Hooks". Live Examples: https://reaml.netlify.com
OCaml
99
star
7

diff.rs

An LCS based slice and string diffing implementation.
Rust
76
star
8

tailwind.run

62
star
9

elm-remotedev

Integration of Elm Application's `update` function with Redux DevTools Extension. An alterative to the official Elm Debugger.
JavaScript
60
star
10

edn.rs

An EDN (Extensible Data Notation) parser in Rust.
Rust
48
star
11

bs-preact

Deprecated in favor of https://github.com/utkarshkukreti/reaml, which has more features, works with the latest BuckleScript, and can be used with both React and Preact.
OCaml
39
star
12

whois.ex

Pure Elixir WHOIS client and parser.
Elixir
27
star
13

munch.rs

Blazing fast, zero-copy parser combinator library for Rust with an elegant API for both strings and bytes.
Rust
21
star
14

purescript-corefn.rs

A parser for PureScript's corefn JSON representation.
Rust
14
star
15

check.c

check.c is a mini testing framework for C that I built to do Test-Driven Development in my C projects.
C
13
star
16

purescript-hertz

PureScript
11
star
17

bootstrap-themes

Open Source, MIT Licensed, Customizable Themes for Bootstrap 4.
HTML
11
star
18

psoc

[WIP] A PureScript to JavaScript compiler focused on increasing performance and decreasing size of the generated code.
Rust
10
star
19

apl-inputrc

Easier way to input APL symbols in GNU APL (or other interactive command line programs).
Ruby
9
star
20

bs-preact-starter

Deprecated in favor of https://github.com/utkarshkukreti/reaml, which has more features, works with the latest BuckleScript, and can be used with both React and Preact.
OCaml
9
star
21

flip-flop.rs

This library implements the [flip-flop operator from Perl and Ruby](https://en.wikipedia.org/wiki/Flip-flop_(programming)) as a Rust macro.
Rust
7
star
22

draco-starter

A starter for https://github.com/utkarshkukreti/draco.
Rust
6
star
23

vite-typescript-library-starter

`mkdir foo && cd foo`; `git clone https://github.com/utkarshkukreti/vite-typescript-library-starter . && rm -rf .git && git init && git add . && git commit -m init && yarn`
TypeScript
6
star
24

wn.rs

Rust
4
star
25

reaml-starter

A starter for [Reaml](https://github.com/utkarshkukreti/reaml) demonstrating a `useReducer` based Counter.
OCaml
4
star
26

catena-r1

A functional, concatenative programming language, inspired by Joy, and implemented in Haskell [Revision 1]
Haskell
4
star
27

zigzag.ex

Zigzag is a fast and flexible parallel processing library for Elixir.
Elixir
3
star
28

parco

A hyper-optimized 1kb library to build fully type-safe parsers in TypeScript.
TypeScript
3
star
29

timingapp.zsh

A simple script to enable directory level tracking for zsh in TimingApp.
Shell
3
star
30

should.c

should.c is a mini testing framework for C, which also happens to be pretty.
C
3
star
31

siphash.rs

Simple and fast implementation of the SipHash hashing algorithm in Rust
Rust
2
star
32

hybrid-core

PHP
2
star
33

rubymotion-breakout

A simple implementation of the Breakout game in RubyMotion.
Ruby
2
star
34

rubymotion-hackernews

Ruby
2
star
35

typescript-preact-tailwind-parcel-starter

TypeScript
2
star
36

phaad

A beautiful way to write PHP code.
Ruby
2
star
37

twitter-angellist-bridge

Major WIP
Ruby
2
star
38

project-euler

Repository of questions of Project Euler that I've solved, in various languages.
Common Lisp
2
star
39

snabbdom-transition

Vue.js inspired transitions component for Snabbdom.
JavaScript
2
star
40

ace_editor-rails

Ace Editor for the Rails pipeline
Ruby
2
star
41

reaml-opinionated-starter

An Opinionated Starter for Reaml which includes Preact, TypeScript, TailwindCSS, Relude, PurgeCSS. Live Demo: https://reaml-opinionated-starter.netlify.com
OCaml
2
star
42

gitstats

Ruby
1
star
43

elm-animate-on-change-poc

https://utkarshkukreti.github.io/elm-animate-on-change-poc/
JavaScript
1
star
44

fropy

Process memory and cpu time benchmarker
Ruby
1
star
45

iff.rs

Rust
1
star
46

gm.ex

Idiomatic GraphicsMagick wrapper for Elixir.
Elixir
1
star
47

bucklescript-minimal-starter

OCaml
1
star
48

rubymotion-chipmunktest

Ruby
1
star
49

nathans-university-pl101

My solutions to Nathan's University's PL101 course, done in both JS and Haskell.
Haskell
1
star
50

ruby-vps

under development
Ruby
1
star
51

rubymotion-snake

Ruby
1
star
52

snipmate-snippets

1
star
53

challenger

Ruby
1
star
54

geoip_server

Ruby
1
star
55

escodegen.rs

Rust
1
star
56

rubymotion-cocos2dbox2dtest

Ruby
1
star
57

select.ex

An Elixir library to extract useful data from HTML documents, suitable for web scraping.
Elixir
1
star
58

elm-inflect

elm-inflect lets you convert a String to its plural, singular, camelCase, and PascalCase forms.
Elm
1
star
59

hapistrano

Ruby
1
star
60

vite-library-starter

TypeScript
1
star
61

qq

A simple utility to store and access key/value pairs from the shell, useful for storing common urls, etc.
Ruby
1
star
62

vite-preact-typescript-tailwind-starter

https://vite-preact-typescript-tailwind-starter.vercel.app
JavaScript
1
star
63

copath_parser

A parser for data from the CoPATH database. Currently on "prostrate" type output can be parsed.
Ruby
1
star
64

purescript-weber

PureScript
1
star
65

putf

Quickly upload files to a remote server, and copy its url to your clipboard.
Ruby
1
star
66

geoip_client

Ruby
1
star
67

sailor

Ruby
1
star
68

calvin

Terse, APL/J/K inspired programming language. Major WIP.
Ruby
1
star
69

euler

Project Euler Solutions in Ruby
Ruby
1
star
70

subtle-lang

Subtle is a Terse, Array based Programming Language, heavily inspired by the K Programming Language, and partly by APL and J.
Ruby
1
star
71

google-codejam-solutions

My Google CodeJam solutions in various languages
1
star
72

typecodec

Under 1kB, fast, type-safe runtime validation of unknown data for TypeScript.
TypeScript
1
star
73

wp

Unofficial git clone of WordPress repository
PHP
1
star
74

ubuntu-scripts

1
star
75

repository_hosting_backup

Backs up all repositories in your RepositoryHosting.com account into a folder.
Ruby
1
star
76

dust-deploy

small server deployment tool for complex environments
Ruby
1
star
77

long_url

Ruby
1
star
78

possible_habtm_bug

Run rake db:migrate && rake db:seed. Code is in db/seeds.rb
Ruby
1
star
79

typescript-react-tailwind-sass-parcel-starter

HTML
1
star
80

gideros-community-libraries

A collection of libraries for Gideros, maintaned by the community.
Shell
1
star
81

ruport_compatible_with_stresser

(Use branch compat) A complete hack to make ruport work with https://github.com/moviepilot/stresser on Ruby 1.9.2
Ruby
1
star
82

elm-css-modules

`elm-css-modules` compiles CSS modules written in CSS, Sass, or SCSS to plain CSS files and generates Elm definitions for every rule.
JavaScript
1
star
83

better_range.rs

An alternative to the std::iter::range* iterators supporting floats and chars, and a fluent interface to construct ranges.
Rust
1
star
84

advent-of-code-2020

Ruby
1
star
85

project-euler-old

Repository of all the questions of ProjectEuler that I've solved, in various languages.
Ruby
1
star