Skip to content

Instantly share code, notes, and snippets.

@williamho
Last active June 29, 2018 15:02
Show Gist options
  • Save williamho/0a90163e552b59cd14fd89f976f243da to your computer and use it in GitHub Desktop.
Save williamho/0a90163e552b59cd14fd89f976f243da to your computer and use it in GitHub Desktop.
hyperapp setup
yarn install
yarn parcel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello world!</title>
</head>
<body>
<script src="index.tsx"></script>
</body>
</html>
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);
{
"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"
}
}
{
"compilerOptions": {
"jsx": "react",
"jsxFactory": "h"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment