Skip to content

Instantly share code, notes, and snippets.

Daniel Steigerwald steida

Block or report user

Report or block steida

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@steida
steida / setImmediate.ts
Created Oct 5, 2019
Minimal modern setImmediate polyfill
View setImmediate.ts
// Draft uses YuzuJS/setImmediate polyfill, which can be reduced to this code.
// But it seems request requestAnimationFrame is good enough.
// TODO: Will it work with queue fix?
// // https://github.com/google/closure-library/blob/master/closure/goog/async/nexttick.js#L209
const setImmediate = (() => {
const channel = new MessageChannel();
let head: any = {};
let tail = head;
channel.port1.onmessage = () => {
if (head.next !== undefined) {
View resolveImmediate.ts
// https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/resolveImmediate.js
const resolvedPromise = Promise.resolve();
function throwNext(error: any) {
setTimeout(() => {
throw error;
}, 0);
}
View useRovingTabIndex.tsx
import React, {
useEffect,
createContext,
FunctionComponent,
useRef,
MutableRefObject,
useCallback,
useContext,
useReducer,
Reducer,
View useLocalStorage.ts
import throttle from 'lodash.throttle';
import React, { Dispatch, SetStateAction, useContext } from 'react';
import WasRenderedContext from '../contexts/WasRenderedContext';
type Key = 'darkMode' | 'tasks' | 'email' | 'version';
type DarkMode = boolean;
interface TaskText {
leaves: Array<{ text: string }>;
@steida
steida / nearest.js
Created Oct 8, 2018
Get nearest day week date defined by week in month
View nearest.js
/* @flow */
import React from 'react';
import { DayOfWeek, LocalDate, TemporalAdjusters } from 'js-joda';
import { FormattedDate } from 'react-intl';
import { ValidationError } from '../../common/lib/validation';
import { connect } from 'react-redux';
import { fields } from '../../common/lib/redux-fields';
import { orderCourse } from '../../common/courses/actions';
import {
Block,
@steida
steida / textinput.js
Created Jun 7, 2018
Textarea auto height for server side rendering
View textinput.js
<TextInput
multiline
// value={value}
defaultValue={value}
onChange={this.handleChange}
placeholderTextColor={placeholderTextColor}
placeholder={intl.formatMessage(messages.placeholder)}
ref={this.inputRef}
style={[
theme.styles.editorTextInput,
View model.graphql
# https://github.com/este/este/wiki/GraphQL
# https://www.prisma.io/features/data-modeling/
# The order of types and consistent relations names is probably a pattern.
type User {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
email: String! @unique
View Page.js
// @flow
import A from './A';
import ErrorPopup from './ErrorPopup';
import Box from './Box';
import Head from 'next/head';
import LoadingBar from './LoadingBar';
import MainNav from './MainNav';
import * as React from 'react';
import SwitchLocale from './SwitchLocale';
import Text from './Text';
View Error.js
// @flow
import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import type { Error as ErrorType } from '../lib/error';
import Text, { type TextProps } from './Text';
export const errorToMessage = (error: ErrorType) => {
switch (error.type) {
case 'required':
return (
@steida
steida / getWeakKey.js
Created Nov 25, 2017
Get React key for immutable object without memory leaks.
View getWeakKey.js
export const getWeakKey = (() => {
const map = new WeakMap();
let idx = 0;
return element => {
if (map.has(element)) return map.get(element);
idx++;
map.set(element, idx.toString());
return idx;
};
})();
You can’t perform that action at this time.