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 / example.js
Last active February 16, 2026 16:23
Preact + Web Components = <333 Demo: http://www.webpackbin.com/VJyU9wK5W
import { h, Component } from 'preact';
import Markup from 'preact-markup';
import register from './preact-custom-element';
// just a proxy component: WC -> Preact -> WC
const A = () => <x-b foo="initial foo from <x-a>" />;
// stateful component that can re-render
class B extends Component {
render(props, state) {
syntax where = function(ctx) {
const binaryOps = ["or", "and", "==", ">", "<", "-", "+", "*", "/", "."];
const dummy = #`dummy`.get(0);
function matchNext(names) {
const marker = ctx.mark();
const next = ctx.next();
ctx.reset(marker);
return !next.done && names.includes(next.value.val());
}
import { createStore, combineReducers } from 'redux'
const createInjectableStore = (createStore) => {
return (reducers) => {
const store = createStore(combineReducers(reducers))
const replace = () => {
store.replaceReducer(combineReducers(reducers))
}
store.injectReducer = (key, reducer) => {
reducers[key] = reducer
declare namespace preact {
interface ComponentProps {
children?:JSX.Element[];
key?:string;
}
interface PreactHTMLAttributes {
key?:string;
}
function shallowEqual(a, b) {
if (a!==b) {
for (let i in a) if (a[i]!==b[i]) return false;
for (let i in b) if (!(i in a)) return false;
}
return true;
}
export function shouldComponentUpdate(props, state) {
return !shallowEqual(props, this.props) || !shallowEqual(state, this.state);
import React from 'react'
const bgStyles = {
strokeWidth: 3,
strokeLinejoin: 'round',
strokeLinecap: 'round',
fill: 'none',
stroke: '#c3fdff'
}
@jesstelford
jesstelford / README.md
Last active August 25, 2026 19:34
Starving the Event Loop with Microtasks

Starving the Event Loop with microtasks

"What's the Event Loop?"

Sparked from this twitter conversation when talking about doing fast async rendering of declarative UIs in Preact

These examples show how it's possible to starve the main event loop with microtasks (because the microtask queue is emptied at the end of every item in the event loop queue). Note that these are contrived examples, but can be reflective of situations where Promises are incorrectly expected to yield to the event loop "because they're async".

  • setTimeout-only.js is there to form a baseline
@developit
developit / framed.js
Last active February 23, 2018 03:39
<Framed /> component. Demo: https://jsfiddle.net/developit/8bb0aejg/
import { h, Component, render } from 'preact';
/** Renders its children inside an iframe.
* @example
* <Framed>
* This is all rendered into
* <strong>an iframe!</strong>.
* </Framed>
*/
export default class Framed extends Component {
@developit
developit / deferred.js
Last active July 9, 2016 18:19 — forked from tec27/deferred.js
An extension of ES6 Promises that allows for easier deferred resolution/rejection
export class Deferred extends Promise {
constructor(executor) {
super( (resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
if (executor) executor(resolve, reject);
});
}
}
@tec27
tec27 / deferred.js
Created July 9, 2016 02:15
An extension of ES6 Promises that allows for easier deferred resolution/rejection
class Deferred extends Promise {
constructor(executor) {
super(executor)
// These will be overwritten by the creator function
this._resolve = null
this._reject = null
}
resolve(value) {