Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
@developit
developit / esnextbin.md
Last active March 10, 2016 23:00
esnextbin sketch
@developit
developit / esnextbin.md
Last active February 9, 2016 00:03
esnextbin sketch
@developit
developit / spin.js
Last active March 4, 2016 01:42
Demo of ora/cli-spinners
var Ora = require('ora'),
spinners = require('cli-spinners');
var spinner = new Ora({
text: ''
});
var index = 0;
var types = Object.keys(spinners);
// - yes, this is the entire implementation
// - no, it doesn't actually depend on preact
export class Provider {
getChildContext () {
let { children, ...context } = this.props;
return context;
}
render ({ children }) {
return children && children[0] || null
}
@developit
developit / _readme.md
Last active February 3, 2017 15:01
Like linkState(), but for Refs.

Simple, unobtrusive add-on to support String refs in Preact, without needing to pull in preact-compat.

Option 1: Add-on

Calling linkRef(componentInstance, refName) returns a "ref proxy" function, which sets this.refs[refName] when called.

import { h, Component } from 'preact';
import linkRef from './linked-ref';
import { h } from 'preact';
export default function cloneElement(vnode, props, ...children) {
return h(
vnode.nodeName,
extend(extend({}, vnode.attributes || {}), props),
children.length ? children : vnode.children
);
}
@developit
developit / fire-event.js
Last active September 13, 2017 14:05
DOM fireEvent
function fireEvent(element, type) {
let e = document.createEvent('Event');
e.initEvent(type);
element.dispatchEvent(e);
}
import { Component } from 'preact';
import { bind } from 'decko';
class MarkdownEditor extends Component {
constructor() {
super()
this.state = { text: '' };
}
@bind
onEdit(text) {
@developit
developit / document-shim.js
Last active August 4, 2022 02:27
Minimal stand-in for a full DOM. Mocks out basic DOM 1 node and attribute manipulation.
var document = global.document = createDocument();
export default document;
function createDocument() {
const NODE_TYPES = {
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2,
TEXT_NODE: 3,
CDATA_SECTION_NODE: 4,
ENTITY_REFERENCE_NODE: 5,
import emitter from 'emitter';
export let { on, off, emit } = emitter();