Skip to content

Instantly share code, notes, and snippets.

View evanrs's full-sized avatar
🏋️‍♂️
Focusing

Evan Schneider evanrs

🏋️‍♂️
Focusing
View GitHub Profile

When it comes to memo'ization any option will be valid if it meets the following three criteria.

1. Will this work be closer to the root, or the leaf?

As we approach the leaves of the component tree the impact of memo'ization will be diminished as the number of impacted children decreases.

As the number of potential children increases we offer a corresponding level of care in making sure our values only update when there's a pertinent change to that value.

2. Where will my work be used?

@evanrs
evanrs / toHTTPie.ts
Created July 9, 2020 14:52
Convert to HTTPie request
import { map } from "lodash";
export type HTTPieOptions = {
method: string;
headers?: Record<string, string>;
body?: string;
data?: unknown[] | Record<string, unknown>;
};
export function toHTTPie(url: string, { method, ...options }: HTTPieOptions) {
@evanrs
evanrs / once.ts
Last active January 29, 2022 04:43
variadic once in typescript
type ArityNone<T> = () => T;
type ArityOne<T, A> = (a?: A) => T;
type ArityTwo<T, A, B> = (a: A, b?: B) => T;
type ArityThree<T, A, B, C> = (a: A, b: B, c?: C) => T;
type ArityFour<T, A, B, C, D> = (a: A, b: B, c: C, d?: D) => T;
export function once<T>(resolver: ArityNone<T>): ArityNone<T>;
export function once<T, A>(resolver: ArityOne<T, A>): ArityOne<T, A>;
export function once<T, A, B>(resolver: ArityTwo<T, A, B>): ArityTwo<T, A, B>;
export function once<T, A, B, C>(resolver: ArityThree<T, A, B, C>): ArityThree<T, A, B, C>;
@evanrs
evanrs / machine.js
Created May 7, 2020 19:58
Generated by XState Viz: https://xstate.js.org/viz
const todoMachine = Machine({
id: "todo",
initial: "reading",
context: {
id: undefined,
title: "",
prevTitle: "",
},
on: {
TOGGLE_COMPLETE: {
@evanrs
evanrs / machine.js
Last active May 7, 2020 19:51
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@evanrs
evanrs / README.md
Last active March 9, 2017 20:16
Debounce a state change, sustain for the duration by repeated calls.

Debounce a state change with a sustain.

This is debounce with true|false passed to the callback.

In this example the value of scrolling will be true during the scroll event and for 250ms after.

import sustain from 'sustain';
let scrolling = false;

sustainScrolling = sustain(250, (state) =&gt; scrolling = state)
@evanrs
evanrs / README.md
Last active December 13, 2016 08:04
Use React in an Angular app

ngReactComponent

Use React in an Angular app.

Bindings are automatically derived from propTypes.

const ngSuchComponent =
  ngReactBridge.create(SuchComponent);

Keybase proof

I hereby claim:

  • I am evanrs on github.
  • I am evanrs (https://keybase.io/evanrs) on keybase.
  • I have a public key ASCWQiYWNQfKYm_IU6kYzsc1TDyhn5m05a_ktY0_OqR3FQo

To claim this, I am signing this object:

@evanrs
evanrs / flatMapObject.js
Last active June 7, 2017 04:22
Functions
import flatMap from 'lodash/flatMap';
import keys from 'lodash/keys';
import get from 'lodash/get';
import identity from 'lodash/identity';
import isArray from 'lodash/isArray';
import isDate from 'lodash/isDate';
import isFunction from 'lodash/isFunction';
import isObject from 'lodash/isObject';
import map from 'lodash/map';
import zipObject from 'lodash/zipObject';
@evanrs
evanrs / react-poll.js
Created February 26, 2016 17:42
Poll at interval or on window focus, throttle between interval and focus events.
import React, { Component, PropTypes } from 'react'
import throttle from 'lodash/throttle';
import attempt from 'lodash/attempt';
class Poll extends Component {
static propTypes = {
throttle: PropTypes.number,
interval: PropTypes.number,
onFocus: PropTypes.func,
onInterval: PropTypes.func