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: | |
const HandleSubmit = (state, formdata) => { | |
// here, formdata will be a js object | |
// where each of the keys corresponds to | |
// the name of a form field, and the | |
// value will be the value of that | |
// form field | |
} |
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 MEMO = [] | |
const mapSub = (M, [fn, props]) => { | |
let result = MEMO.filter( | |
([f, p, r]) => f === fn && shallowEqual(props, p) | |
).reduce((_, [f, p, r]) => r, null) | |
if (!result) { | |
result = mapEffect(M, [fn, props]) | |
MEMO.push([fn, props, result]) |
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 (Element.prototype._lifecycle) return | |
Element.prototype._lifecycle = true | |
const remove = Element.prototype.removeChild | |
Element.prototype.removeChild = function(child) { | |
const ret = remove.apply(this, [child]) | |
child.dispatchEvent(new Event('remove')) | |
return ret |
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 withHead = (() => { | |
let _setHead = null | |
let setHead = nodes => { | |
if (_setHead) return _setHead(nodes) | |
app({ | |
init: nodes, | |
view: nodes => nodes, | |
node: document.head, | |
middleware: d => (_setHead = d), | |
}) |
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
var sub = function(fn) { | |
return function(action) { | |
return [fn, {action: action}] | |
} | |
} | |
var throttledEvent = function(name) {} | |
var rawEvent = function(name) { | |
return sub(function(dispatch, props) { |
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 updatePosition = elem => { | |
const {top: newY, left: newX} = elem.getBoundingClientRect() | |
elem._x = newX | |
elem._y = newY | |
return [newX, newY] | |
} | |
const slide = (elem, {time=300, easing='ease-in-out', delay=0}) => { | |
const oldX = elem._x | |
const oldY = elem._y |
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 resolve = (node, state) => { | |
if (node == null) { | |
//just return it | |
} else if (Array.isArray(node)) { | |
node = node.map(function (n) { return resolve(n, state)}) | |
node = Array.prototype.concat.apply([], node) | |
node = node.filter(function (n) { return n != null }) | |
} else if (node.name === '$') { | |
node = resolve(node.props.f(state), state) | |
} else if (node.children) { |
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> | |
<style> | |
.gauge { | |
position: relative; | |
padding: 0; | |
border: 1px #555 solid; | |
background-color: #aaa; |
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> | |
<style> | |
.gauge { | |
position: relative; | |
padding: 0; | |
border: 1px #555 solid; | |
background-color: #aaa; |
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> | |
<style> | |
.gauge { | |
position: relative; | |
padding: 0; | |
border: 1px #555 solid; | |
background-color: #aaa; |