Skip to content

Instantly share code, notes, and snippets.

View binaryta's full-sized avatar
🍜

binaryta binaryta

🍜
View GitHub Profile
{
"name": "hyperapp_typescript_introduction",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"awesome-typescript-loader": "^3.4.1",
"babel": "^6.23.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
const path = require('path');
module.exports = {
entry: [path.resolve(__dirname, './src/app.ts')],
output: {
filename: 'bundle.js',
path: path.join(__dirname, 'public/')
},
module: {
rules: [
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>hyperapp + typescript sample</title>
</head>
<body>
<script src="bundle.js"></script>
</body>
</html>
export interface State {
count: number;
}
export const state: State = {
count: 0
}
import { ActionsType, ActionResult } from "hyperapp"
import { State } from "./state"
export interface Actions {
down: (value: number) => (state: State) => ActionResult<State>;
up: (value: number) => (state: State) => ActionResult<State>;
}
export const actions: ActionsType<State, Actions> = {
down: (value: number) => (state) => {
import { h, app, View } from "hyperapp"
import { state, State } from "./state"
import { actions, Actions } from "./actions"
export 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>
import { h, app } from "hyperapp"
import { state, State } from "./state"
import { actions, Actions } from "./actions"
import { view } from "./view.tsx"
app<State, Actions>(state, actions, view, document.body);