Skip to content

Instantly share code, notes, and snippets.

@lukejacksonn
Created March 30, 2017 03:26
Show Gist options
  • Save lukejacksonn/e40c97ce4215ac60b041fa4d928a7d77 to your computer and use it in GitHub Desktop.
Save lukejacksonn/e40c97ce4215ac60b041fa4d928a7d77 to your computer and use it in GitHub Desktop.
Multiple hyperapps on one page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Examples</title>
<script src="https://unpkg.com/hyperapp"></script>
<script src="https://unpkg.com/babel-standalone"></script>
<script type="text/babel">
const { h, app } = hyperapp
/** @jsx h */
// *****************************
// Static model example
app({
model: "Hello World",
view: model => <h1>{model}</h1>
})
// *****************************
// Dynamic model example
app({
model: new Date().toString(),
view: model =>
<div>
<h1>Todays Date</h1>
<p>{model}</p>
</div>
})
// *****************************
// Interactive Example
app({
model: 0,
actions: {
increment: model => model + 1
},
view: (model, actions) =>
<button onclick={actions.increment}>{model} clicks</button>
,
hooks: {
onUpdate: (oldModel, newModel) => console.log('Update:', oldModel, newModel),
onAction: (action) => console.log('Action:', action),
}
})
</script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment