yarn install
yarn parcel
Last active
June 29, 2018 15:02
-
-
Save williamho/0a90163e552b59cd14fd89f976f243da to your computer and use it in GitHub Desktop.
hyperapp setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello world!</title> | |
</head> | |
<body> | |
<script src="index.tsx"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { h, app, ActionsType, ActionResult, View } from "hyperapp"; | |
interface State { | |
count: number; | |
}; | |
const state: State = { | |
count: 0 | |
}; | |
interface Actions { | |
down: (value: number) => (state: State) => ActionResult<State>; | |
up: (value: number) => (state: State) => ActionResult<State>; | |
}; | |
const actions: ActionsType<State, Actions> = { | |
down: (value: number) => (state) => { | |
return { count: state.count - value }; | |
}, | |
up: (value: number) => (state) => { | |
return { count: state.count + value }; | |
} | |
}; | |
const view: View<State, Actions> = (state, actions) => ( | |
<div> | |
<h1>{state.count}</h1> | |
<button onclick={() => actions.down(1)}>-</button> | |
<button onclick={() => actions.up(1)}>+</button> | |
</div> | |
); | |
app(state, actions, view, document.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "hello", | |
"version": "1.0.0", | |
"main": "index.html", | |
"license": "MIT", | |
"devDependencies": { | |
"parcel": "^1.9.3", | |
"typescript": "^2.9.2" | |
}, | |
"dependencies": { | |
"hyperapp": "^1.2.6" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"jsx": "react", | |
"jsxFactory": "h" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment