Skip to content

Instantly share code, notes, and snippets.

View jord-goldberg's full-sized avatar

Jordan Goldberg jord-goldberg

  • New York, NY
View GitHub Profile
declare module 'styled-transition-group' {
import type { TransitionProps as TProps } from 'react-transition-group/Transition';
import type {
AnyStyledComponent,
DefaultTheme as Theme,
StyledComponentInnerAttrs,
StyledComponentInnerComponent,
StyledComponentInnerOtherProps,
ThemedStyledFunction,
} from 'styled-components';
@jord-goldberg
jord-goldberg / ScimPatch.js
Created July 7, 2021 20:11
create a SCIM patch request body based on diff between Javascript objects.
import isEqual from "lodash/isEqual";
import isObject from "lodash/isObject";
const flattenPaths = (value, path = []) => {
if (!isObject(value)) {
return { [path.join(".")]: value };
}
if (Array.isArray(value)) {
return value.reduce((cumulative, item) => {
cumulative[`${path.join(".")}[value eq "${item.value}"]`] = item;
@jord-goldberg
jord-goldberg / batchActionsMiddleware.ts
Last active June 6, 2021 14:50
React-redux batch actions middleware typed using variadic tuples
import { batch } from 'react-redux';
import {
Action,
AnyAction,
Middleware,
ThunkAction,
ThunkDispatch,
} from '@reduxjs/toolkit';
type MaybeThunkAction<T> = T extends Action
import set from "lodash/set";
import { createAction, createSlice } from "@reduxjs/toolkit";
import { all, fork } from "redux-saga/effects";
const isValidFeatureSaga = saga =>
typeof saga === "function" || typeof saga?.worker === "function";
const getType = (featureName, actionKey) => `${featureName}/${actionKey}`;
/**
@jord-goldberg
jord-goldberg / useVideoFrames.ts
Last active March 22, 2024 14:35
useVideoFrames react hook - a callback for every frame of a video element
import React, { useEffect, useRef, useState } from "react";
type VideoEventListenerMap = {
[EventName in keyof HTMLMediaElementEventMap]?: EventListener;
};
const useVideoFrames = (
frameCallback = (videoTime: number) => {}
): [HTMLVideoElement | null, React.RefCallback<HTMLVideoElement>] => {
const [video, setVideo] = useState<HTMLVideoElement | null>(null);
@jord-goldberg
jord-goldberg / styled-system.d.ts
Last active March 15, 2021 17:45
Opinionated styled-system css and variant function typings that enforce use of theme-defined values.
/**
* `Multiples`, `Scales` & `Aliases` types from
* [@styled-system/css](https://github.com/styled-system/styled-system/blob/master/packages/css/src/index.js)
*/
declare module "@styled-system/css" {
import * as CSS from "csstype";
export interface Theme {}
type CSSPropertiesFallback = CSS.PropertiesFallback<number | string>;