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
// Serialise command-line parameters of form: | |
// `--boolean`, `--key=value`, `--multiple:value1 --multiple:value2` | |
export default args => args.reduce((input, arg) => { | |
const [param, key, verb, value] = (/--(\w+)(=|:)?(.+)?/).exec(arg) || [] | |
if (param) | |
input[key] = ( | |
// No verb means boolean; '=' means direct assignment; ':' means accumulate array | |
!verb ? true : verb == "=" ? value : !input[key] ? [value] : [...input[key], value] | |
) |
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
|
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
export default function changeTag(original, tagName){ | |
// Create a replacement tag of the desired type | |
const replacement = document.createElement(tagName) | |
// Grab all of the original's attributes, and pass them to the replacement | |
Array.prototype.forEach.call(original.attributes, ({name, value}) => { | |
replacement.setAttribute(name, value) | |
}) | |
// Persist contents |
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 muty from 'muty' | |
export default function ui_io(callback = Function.prototype){ | |
const {addEventListener} = EventTarget.prototype | |
const promises = [] | |
const listeners = [] | |
const logs = [] | |
function register(entry){ |
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 {addEventListener} = EventTarget.prototype | |
export default function EventListenerListener({ | |
blocking = false, | |
removing = true, | |
visitor = Function.prototype, | |
} = {}){ | |
if(this instanceof EventListenerListener){} | |
else return new EventListenerListener(...arguments) | |
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 muties = new Set | |
class Muty extends MutationObserver { | |
observe(){ | |
muties.add(this) | |
super.observe(...arguments) | |
} | |
disconnect(){ |
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 css from './css.js' | |
let color = 'red' | |
let fontFamily = 'sans-serif' | |
m.mount(document.body, { | |
view: () => [ | |
m('p', | |
css` | |
color: ${ color }; |
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
// Async generators don't actually work this way: all yields implictly mandate asynchronous (non-synchronously-blocking) resolution under the hood; so in practice it's probably better to be honest and make this unambiguously wasteful & imprecise and have all steps as explicit awaits. 🙄 | |
const KitchenSink = steps(async function * ($){ | |
$.view(v => | |
m('p.counter', $.attrs.value, '!') | |
) | |
yield $.create | |
style({ | |
transition : 'none', |
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
customElements.define('life-cycle', class LifeCycle extends HTMLElement { | |
constructor(){ | |
super() | |
} | |
connected(){} | |
connectedCallback(){ | |
this.style.display = 'contents' | |
this.connected(...arguments) |