import {h, text, app} from "hyperapp"
app({
view: () => h('main', {}, text('text')),
// cast to Node only if you're sure it exists
node: document.getElementById('app') as Node,
})
This file contains hidden or 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
/** | |
* Utility for testing hyperapp app/state logic. Pass it an init parameter | |
* and an effectHandler - a function that will replace every effecter used | |
* it will be called with (originalEffecter, payload) every time an effect | |
* is used allowing you to ovverride it and test that the right effecter | |
* was called, et c. | |
* | |
* Returns an object with some useful functions: getState allows you to | |
* inspect the state at any time, stop stops the app. dispatch dispatches | |
* actions. |
This file contains hidden or 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
//COMPARE: | |
let page; | |
switch (hash) { | |
case '#about': | |
page = 'about' | |
break; | |
case '#photos': | |
page = 'photos' |
This file contains hidden or 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 } from "hyperapp" | |
/** @template S @typedef {import('hyperapp').VNode<S>} VNode */ | |
/** @template S @typedef {import('hyperapp').MaybeVNode<S>} MaybeVNode */ | |
/** @template S @typedef {import('hyperapp').ElementVNode<S>} ElementVNode */ | |
/** @template S @typedef {MaybeVNode<S> | MaybeVNode<S>[]} Content */ | |
/** @template S @typedef {import('hyperapp').Props<S>} Props */ | |
/** @template S,X @typedef {import('hyperapp').CustomPayloads<S,X>} CustomPayloads */ | |
/** @type {<S>(props: (Props<S> | Content<S>)) => props is Props<S>} */ |
This file contains hidden or 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
/* | |
When you are developing using a live-reloading server, it can be | |
annoying when the state keeps resetting. This middleware (just | |
meant for debugging) persists state across reloads so you see | |
immediate changes on what you were workig on, without extra steps | |
over and over to get back to where you were. | |
Usage: |
This file contains hidden or 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
/* | |
Apparently this script produces too high number of valid passports. Unclear why | |
*/ | |
const required = ['byr','iyr','eyr','hgt','hcl','ecl','pid'] | |
const byrValid = x => { | |
if (!x.match(/^\d{4}$/)) return false | |
if (+x > 2002) return false | |
if (+x < 1920) return false |
This file contains hidden or 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> | |
<script type="module"> | |
/* | |
Plain h - 33.4 fps | |
[email protected] - 30.0 fps (10% slower) – 825 bytes | |
[email protected] - 28.5 fps (15% slower) – 674 bytes | |
*/ |
This file contains hidden or 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 default (g => f => (...a) => [g, { f, a }])((d, { f, a }) => f(d, ...a)) | |
/* | |
Usage like: | |
import fx from 'fx.js' | |
const jsonLoader = fx((dispatch, url, then) => | |
fetch(url) |
This file contains hidden or 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
/* | |
Usage: | |
import addStyleSheet from 'add-stylesheet.js' | |
export const view = () => ( | |
<div class="container"> | |
<h1>Hello</h1> | |
<p>World</p> | |
</div> | |
) |
This file contains hidden or 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
/* | |
If you ever end up writing deep sideways pyramids of | |
setTimeouts, you can use this utility to sequentialize | |
them. | |
step(a).step(b).step(c) | |
is equivalent to |
NewerOlder