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
@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) {
@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);
});
}
}
@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 {
@jesstelford
jesstelford / README.md
Last active February 13, 2026 07:30
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
@tj
tj / Connector.js
Last active November 26, 2019 15:43
import React from 'react'
const bgStyles = {
strokeWidth: 3,
strokeLinejoin: 'round',
strokeLinecap: 'round',
fill: 'none',
stroke: '#c3fdff'
}
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);
declare namespace preact {
interface ComponentProps {
children?:JSX.Element[];
key?:string;
}
interface PreactHTMLAttributes {
key?:string;
}
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
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());
}