View promise-getters.md

Functions rescue us in this case because functions are lazy. But now, we can’t chain these things with .then() anymore.

function lazyPromise() {
  return new Promise(resolve => setTimeout(resolve, 1000))
    .then(() => console.log('Chain off all'));
}
// The only location you can't chain off is the function

// Chains just fine this way
View concept.js
// Create virtual document and documentElement.
const vdoc = document.createVirtualDocument();
const root = vdoc.createDocumentElement('html');
// <template/> tags should be able to be converted as well.
const someTemplate = document.querySelector('template#some-template');
// Add some SVG.
root.appendChild(vdoc.createElement({
nodeName: 'svg',
namespaceURI: 'http://www.w3.org/2000/svg',
View acceleration.sh
touchpad_id=$(xinput --list | grep "TouchPad" | xargs -n 1 | grep "id=" | sed 's/id=//g')
accel_speed_code=$(xinput --list-props $touchpad_id | awk '/Accel Speed \(/ {print $4}' | grep -o '[0-9]\+')
# Default acceleration is too slow (non-existent)
xinput --set-prop $touchpad_id $accel_speed_code .75
View fixture.js
const { render } = require('react-dom');
const mount = document.querySelector('main');
class Root {
render() {
return (
<div>Hello world</div>
);
}
}
View example.js
import { innerHTML } from 'diffhtml'
// Start simple...
innerHTML(document.body, `
<marquee>Go for it!</marquee>
`)
// Move to template engine if you want
innerHTML(document.body, mustache.render(`
<div>
View abortable-promise.js
class AbortablePromise extends Promise {
constructor(fn) {
let _reject = null;
super((resolve, reject) => {
_reject = reject;
return fn(resolve, reject);
});
this.abort = () => {
View _setup.sh
npm i jsdom-wc@11.0.0-alpha-1
View make-element.js
// Allow the user to invoke the Custom Element chain.
function makeElement(tagName, props) {
const Constructor = customElements.get(tagName);
if (Constructor) {
return new Constructor(props);
}
else {
document.createElement(tagName);
}
View web-component-jsx.js
import { innerHTML, createTree } from 'diffhtml';
import WebComponent from 'diffhtml-components/web-component';
import PropTypes from 'proptypes';
customElements.define('jsx-test', class extends WebComponent {
render({ message }) {
return (
<div>{message}</div>
);
}
View importScript.js
Object.defineProperty(window, Symbol.for('registry'), {
value: new Map(),
});
window.importScript = src => {
const registry = window[Symbol.for('registry')];
if (registry.has(src)) {
return registry.get(src).promise;
}