Skip to content

Instantly share code, notes, and snippets.

View j-hannes's full-sized avatar
💭
hello world

Johannes Erber j-hannes

💭
hello world
View GitHub Profile
@j-hannes
j-hannes / Main.elm
Last active October 4, 2016 13:13
Hello world example from elm-lang.org
module Main exposing (..)
import Html exposing (Html, span, text)
import Html.Attributes exposing (class)
main : Html a
main =
span [ class "welcome-message" ] [ text "Hello, World!" ]
@j-hannes
j-hannes / app.js
Last active May 22, 2016 16:10
redux counter in es6
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
const INCREMENT = 'INCREMENT'
const DECREMENT = 'DECREMENT'
const reducer = (state = 0, action) => {
switch (action.type) {
case INCREMENT:
@j-hannes
j-hannes / Counter.elm
Last active May 21, 2016 21:21
Adding DOM events
import Html.Events exposing (onClick)
-- other code
view state =
div []
[ button [onClick Decrement] [ text "-" ]
, span [] [ text (toString state) ]
, button [onClick Increment] [ text "+" ]
]
@j-hannes
j-hannes / Counter.elm
Last active May 21, 2016 21:02
Final version (without types)
module Counter exposing (..)
import Html exposing (button, div, span, text)
import Html.App as Html
import Html.Events exposing (onClick)
main =
Html.beginnerProgram { model = 0, view = view, update = update }
@j-hannes
j-hannes / Counter.elm
Last active May 21, 2016 20:47
Update application state
update action state =
case action of
Increment ->
state + 1
Decrement ->
state - 1
@j-hannes
j-hannes / Counter.elm
Last active May 21, 2016 20:47
Separate main and view
import Html.App as Html
main =
Html.beginnerProgram { model = 0, view = view, update = update }
view state =
div []
[ button [] [ text "-" ]
@j-hannes
j-hannes / Counter.elm
Last active May 21, 2016 20:46
Action types
type Action
= Increment
| Decrement
@j-hannes
j-hannes / index.html
Created May 21, 2016 20:34
Counter HTML
<!doctype html>
<html>
<head>
<title>a simple elm counter</title>
</head>
<body>
<div id="counter"></div>
<script src="counter.js"></script>
<script>
@j-hannes
j-hannes / Counter.elm
Last active May 21, 2016 20:32
Counter v1
module Counter exposing (..)
import Html exposing (button, div, span, text)
main =
div []
[ button [] [ text "-" ]
, span [] [ text "0" ]
, button [] [ text "+" ]
@j-hannes
j-hannes / webpack.config.js
Last active May 21, 2016 20:24
for redux counter
module.exports = {
entry: './app.js',
output: {
path: './',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,