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 { app, h } from "hyperapp"; | |
import { Stateful } from './helpers' | |
/* Working example, https://codepen.io/sergey-shpak/pen/maMopd */ | |
// --- STATEFUL COMPONENT --- | |
// Don't use arrow functions for stateful components/actions | |
// Since context is linked to it's definition context |
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 { 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]) |
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 { app, h } from 'hyperapp'; // V2 | |
// DOM Effect | |
// Observer Implementation | |
// Will be moved to subscriptions package | |
const find = (query, nodes, cb) => nodes.forEach(node => { | |
if(node.nodeType !== 1 ) return | |
if(Object.keys(query).every(key => node.getAttribute(key) === query[key])) | |
return cb(node) | |
else if(node.childNodes.length) |
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
/* | |
Implements actions composition for Hyperapp#v2 | |
Usage examples: | |
const actionA = state => ({ property: 'A' }) | |
const actionB = state => ({ property: state.property + 'B' }) | |
const composition = compose(actionA, actionB) |
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 } 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 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 { exec } = require('child_process'); | |
// Compile 'git log' command | |
const command = params => | |
`git log --pretty=format:" | |
${params.join(command.format.param)} | |
${command.format.line}"`; | |
const hash = 451436388.16325235; //Math.random()*10e8; | |
command.format = { |
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
// 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 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
/* | |
Implements computed properties for Hyperapp#v2 | |
It's not recomended approach to use | |
unless you really know what you're doing | |
Usage examples: | |
// action is triggered whenever state.property updated* |
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
/* | |
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)) |
NewerOlder