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": "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", |
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
const path = require('path'); | |
module.exports = { | |
entry: [path.resolve(__dirname, './src/app.ts')], | |
output: { | |
filename: 'bundle.js', | |
path: path.join(__dirname, 'public/') | |
}, | |
module: { | |
rules: [ |
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> | |
<head> | |
<meta charset="utf-8"/> | |
<title>hyperapp + typescript sample</title> | |
</head> | |
<body> | |
<script src="bundle.js"></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
export interface State { | |
count: number; | |
} | |
export const state: State = { | |
count: 0 | |
} |
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 { 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) => { |
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, 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> |
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 } 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); |