Skip to content

Instantly share code, notes, and snippets.

@bvaughn
bvaughn / react-dom.development.cjs.diff
Last active August 31, 2018 18:39
React PR #13509 bundle diffs
1c1
< /** @license React v16.4.2
---
> /** @license React v16.4.3-alpha.0
18d17
< var invariant = require('fbjs/lib/invariant');
20,21d18
< var warning = require('fbjs/lib/warning');
< var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
23d19
@bvaughn
bvaughn / create-subscriber-component-poc.js
Last active September 30, 2018 09:55
create-subscriber-component proof of concept
type SubscribableConfig = {
// Maps property names of subscribable data sources (e.g. 'someObservable'),
// To state names for subscribed values (e.g. 'someValue').
subscribablePropertiesMap: {[subscribableProperty: string]: string},
// Synchronously get data for a given subscribable property.
// It is okay to return null if the subscribable does not support sync value reading.
getDataFor: (subscribable: any, propertyName: string) => any,
// Subscribe to a given subscribable.
import React, { Component, Fragment, Suspense } from 'react';
import read from './Resource';
// Wait long enough for DevTools to see
const wait = (ms = 1) => {
const startTime = performance.now();
while (performance.now() - startTime < ms) {
// ...
}
};
import React, {useEffect, useRef, useState} from 'react';
import {Animated, Text} from 'react-native';
// Begin https://unpkg.com/react-native-animation-hooks@1.0.1/build/AnimationHooks.js
export const useAnimatedValue = initialValue => {
const ref = useRef(new Animated.Value(initialValue));
return ref.current;
};
const getInitialValue = config => {
if (typeof config.initialValue !== 'undefined') return config.initialValue;
@bvaughn
bvaughn / profile-data.json
Created April 1, 2019 00:00
Sample React DevTools profiling data export
{
"version": 1,
"profilingSummary": {
"commitDurations": [
8.130000089295208,
2.7099999133497477,
0.40499994065612555,
0.3299998352304101,
0.3400000277906656,
0.33000006806105375,
{
"version": 2,
"profilingSummary": {
"commitDurations": [
2.555000042775646,
0.0450000079581514,
0.054999967687763274,
2.4800000683171675,
0.03999999898951501,
0.0350000336766243,
@bvaughn
bvaughn / test-utils-mock-component-alternatives.js
Created July 11, 2018 19:36
Alternatives for deprecated ReactTestUtils.mockComponent()
// Let's say you have a component (LoadingComponent),
// That renders a placeholder when props.isLoading is true,
// And renders a ChildComponent when props.isLoading is false.
function LoadingComponent(props) {
const { isLoading, ...rest } = props;
if (isLoading) {
return null;
} else {
return <ChildComponent {...rest} />;
}
@bvaughn
bvaughn / redux-localStorage-module.js
Last active August 4, 2019 20:11
Redux + localStorage
/** @flow */
import Immutable from 'immutable'
import { createSelector } from 'reselect'
const LOCAL_STORAGE_KEY = 'LocalStorageModule'
const ACTION_TYPES = {
REMOVE: 'REMOVE_ACTION',
SET: 'SET_ACTION'
}
@bvaughn
bvaughn / Selectable.jsx
Last active August 27, 2019 17:54 — forked from AlexFrazer/Selectable.jsx
Fork of gist.github.com/AlexFrazer/aed3810407aaf23b23168449a7ef83bf to answer question
import * as React from "react";
import * as rbush from "rbush";
export const SelectableContext = React.createContext();
export class SelectableGroup extends React.PureComponent {
static defaultProps = {
tolerance: 10
};
const jestDiff = require("jest-diff");
describe("error boundaries", () => {
let BrokenRender;
let DidCatchErrorBoundary;
let GetDerivedErrorBoundary;
let React;
let ReactNoop;
let ReactFeatureFlags;
let ReactTestRenderer;