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
const {h, app} = hyperapp // @jsx h | |
// Effect for element side-effects | |
const fx = a => (...b) => [a, b] | |
const withElement = fx((dispatch, [element, props], action) => { | |
Object.keys(props).map(k => props[k] && element[k]()) | |
action && dispatch(action) | |
}) | |
// Decoder to get 'event.detail' |
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, app } from 'hyperapp' | |
import { logger } from 'helpers/logger' | |
const init = () => ({ initalized: true }) | |
app({ init }, logger(process.env.NODE_ENV==='development')) |
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' | |
import Lifecycle, { withChildLifeCycle } from 'lifecycle' | |
// 'customEvent.detail' contains element triggered lifecycle event | |
// please use effects to properly manipulate dom element | |
const action = (state, customEvent) => state | |
// and somewhere | |
<Lifecycle> | |
<div oncreated={ action }>created</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
'use strict' // Strict mode to throw mutation errors | |
import { h, app } from 'hyperapp' | |
import { immutable } from 'helpers' | |
// action that is trying to mutate the state | |
// will throw error for any mutation | |
const onclick = state => { | |
++state.counter | |
return state | |
} |
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
/* | |
As you may know fetch requests can be aborted only with AbortController | |
https://developer.mozilla.org/ru/docs/Web/API/AbortController | |
The 'request helper' is exposing abort method into promise, | |
allowing aborting from outside of the promise, for example: | |
``` | |
import { request } from 'helpers' | |
request('https://some/path') | |
.then(response => response.json()) | |
.catch(e => console.log(e)) |
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
// Hyperapp#2 Helmet Component | |
// This is based on Hyperapp Portal helper and Lifecycle events helper | |
// https://gist.github.com/sergey-shpak/88962fdb4002d9a77d315ee9769e6efb | |
// https://gist.github.com/sergey-shpak/c1e0db3d52019eecb0b5717e8cbf00ad | |
const Portal = target => (props, child) => | |
h('source', { // <- any non-space element | |
appendChild: target.appendChild.bind(target), | |
removeChild: target.removeChild.bind(target) |
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 { html } from 'path/to/html' | |
import { app } from 'hyperapp#2' | |
// define any html tag | |
const { div, span } = html | |
// following syntax is supported | |
// tag(attrs) | |
// tag([child]) | |
// tag(attrs, [child]) |
OlderNewer