Skip to content

Instantly share code, notes, and snippets.

const values = {
foo: {
foo: [
{
foo: {
foo: {
foo: {
foo: 'bar',
},
},
function useUnmountSafeReducer<R extends React.Reducer<any, any>>(
reducer: R,
initialState: React.ReducerState<R>,
): [React.ReducerState<R>, React.Dispatch<React.ReducerAction<R>>] {
const [state, rawDispatch] = React.useReducer(reducer, initialState);
const dispatchRef = React.useRef(rawDispatch);
React.useEffect(
(): (() => void) => (): void => {
class PersistentComponent extends React.PureComponent {
static propTypes = {
promise: PropTypes.object.isRequired,
restore: PropTypes.function.isRequired,
children: PropTypes.node,
};
state = {
pending: true,
};
const updateVisibility = state => {
let childVisibility = state.childVisibility;
let currentWidth = 0;
state.children.forEach(element => {
const key = element.props.key;
const elementWidth = state.childWidths[key];
currentWidth += elementWidth;
@10xjs
10xjs / set.js
Last active April 28, 2018 04:44
// Recursive object set.
const set = (object = {}, path, value) => path.length
? {
...object,
[path[0]]: path.length > 1
? set(object[path[0]],path.slice(1), value)
: value,
}
: object;
// @flow
// Import modules ==============================================================
import * as React from 'react';
const buttonSizes = {
small: {
height: 32,
fontSize: 14,
padding: 12,
// @flow
// =============================================================================
// Import modules.
// =============================================================================
import {cloneElement} from 'react';
// SVG Elements with a default black fill.
const DEFAULT_FILLED = new RegExp(`^${[
'path',
@10xjs
10xjs / measureScrollbars.js
Created March 10, 2018 07:04
🔥🔥🔥
const measureScrollbars = (): {width: number, height: number} => {
const container = document.createElement('div');
container.style.width = '100px';
container.style.height = '100px';
container.style.overflow = 'scroll';
const liner = document.createElement('div');
liner.style.width = '200px';
liner.style.height = '200px';
const patch = (target, func) => {
const original = target[func];
target[func] = function () {
return Promise.reolve(original.apply(this, arguments));
};
}
const targets = [
[window, 'fetch'],
// @flow
type Result<T> = {
url: string;
status: number;
body: T;
};
type Handlers<T = mixed> = [
(Response) => Promise<Result<T>>,