Skip to content

Instantly share code, notes, and snippets.

@janwirth
Created October 31, 2019 18:13
Show Gist options
  • Save janwirth/f5c39191268d710d2e91d83feb8dfec7 to your computer and use it in GitHub Desktop.
Save janwirth/f5c39191268d710d2e91d83feb8dfec7 to your computer and use it in GitHub Desktop.
Hyperapp test app
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module">
import { h, app } from "https://unpkg.com/hyperapp"
import {Http} from "https:/unpkg.com/hyperapp-fx@next?module"
const GotCats = (state, [cat]) => {
console.log(cat)
return {catPicture : cat.url, situation : "cat"}
}
const Ring = (state) => [
{...state, situation: "ringed"}
, Http({ // <---
url: "https://api.thecatapi.com/v1/images/search?size=full&limit=1", // <---
response: "json", // <---
action: GotCats, // <---
})
]
app({
init: {situation : "not_ringed", catPicture : null},
view: ({situation, catPicture}) =>
h("main", {}, [
h("h1", {}, "Home of the the Blans"),
h("button", { onClick: Ring }, "RING RING"),
situation == 'not_ringed'
? h("p", {}, "Come on! Do It!")
: situation == "ringed"
? h("p", {}, "Sorry der Blans is zu behizzt. Kann ich leider nicht die Tür öffnen...")
: situation == "cat"
? [h("p", {}, "Aber die cat is da!"), h("img", {src: catPicture})]
: h("p", {}, "App kaput")
]),
node: document.getElementById("app")
})
</script>
</head>
<body>
<main id="app"></main>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment