Current version: 1.0.19 1.0.15 (as of 2018-12-10)
This file contains hidden or 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
| class Deferred extends Promise { | |
| constructor(executor) { | |
| super(executor) | |
| // These will be overwritten by the creator function | |
| this._resolve = null | |
| this._reject = null | |
| } | |
| resolve(value) { |
This file contains hidden or 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 class Deferred extends Promise { | |
| constructor(executor) { | |
| super( (resolve, reject) => { | |
| this.resolve = resolve; | |
| this.reject = reject; | |
| if (executor) executor(resolve, reject); | |
| }); | |
| } | |
| } |
This file contains hidden or 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 { 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 { |
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.jsis there to form a baseline
This file contains hidden or 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 React from 'react' | |
| const bgStyles = { | |
| strokeWidth: 3, | |
| strokeLinejoin: 'round', | |
| strokeLinecap: 'round', | |
| fill: 'none', | |
| stroke: '#c3fdff' | |
| } |
This file contains hidden or 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
| 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); |
This file contains hidden or 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
| declare namespace preact { | |
| interface ComponentProps { | |
| children?:JSX.Element[]; | |
| key?:string; | |
| } | |
| interface PreactHTMLAttributes { | |
| key?:string; | |
| } |
This file contains hidden or 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 { 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 |
This file contains hidden or 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
| 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()); | |
| } |