Skip to content

Instantly share code, notes, and snippets.

View sergey-shpak's full-sized avatar

Sergey sergey-shpak

View GitHub Profile
@sergey-shpak
sergey-shpak / hyperapp-stateful-component-example.js
Last active July 19, 2023 19:35
Hyperapp#v2 Stateful component
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
@sergey-shpak
sergey-shpak / compose.js
Last active November 7, 2019 15:07
Hyperapp#v2 actions composition
/*
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)
@sergey-shpak
sergey-shpak / computed.js
Last active September 26, 2019 21:02
Hyperapp V2 computed properties
/*
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*
@sergey-shpak
sergey-shpak / lens.js
Last active May 25, 2019 13:02
Hyperapp V2 actions state lens
/*
This is variation of `squirrel` and `namespace` approaches
https://gist.github.com/zaceno/0d7c62be81a845857e755c1378b7dbff
https://gist.github.com/sergey-shpak/5817bf146cb970bc4e259aef71b89ef4
Simplifies Hyperapp#v2 actions work with deeply nested state
(updated to support returned actions, parameterized actions)
Usage examples:
@sergey-shpak
sergey-shpak / README.md
Last active December 16, 2018 10:26
Hyperapp#v2 State Namespaces

It's more preferable to use lens.js or squirrel.js


Hyperapp#v2 doesn't have slices/namespaces anymore, so whenever you are working with deeply nested state you have to merge all parents each time:

@sergey-shpak
sergey-shpak / hyperapp.js
Created October 9, 2018 00:08
Hyperapp DOM Observer Subscription (MutationObserver) Implementation
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)
@sergey-shpak
sergey-shpak / git-log-to-json.js
Last active October 23, 2019 18:55
Git log to json (git changelog nodejs)
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 = {
@sergey-shpak
sergey-shpak / Icon.js
Last active March 26, 2019 09:38
@hyperapp font-awesome Icon component
import { h } from 'hyperapp';
export default (props) => {
const {
src: {
icon: [
iconWidth,
iconHeight,
, ,
iconPath,