Skip to content

Instantly share code, notes, and snippets.

View barbogast's full-sized avatar

Benjamin Arbogast barbogast

View GitHub Profile
@barbogast
barbogast / schemaTypes.ts
Created May 18, 2020 15:00
Typescript Definitions for Sanity schemas
import { ReactElement } from 'react'
import { ReactComponentLike } from 'prop-types'
type Meta = {
parent: { [key: string]: any }
path: string[]
document: { [key: string]: any }
}
type CustomRuleCallback = (field: any, meta: Meta) => true | string | Promise<true | string>
# Get the Git branch
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Source: kirsle.net/wizards/ps1.html
export PS1="\[$(tput setaf 6)\]\w\[$(tput setaf 3)\]\$(parse_git_branch) \[$(tput sgr0)\]"
@barbogast
barbogast / middleware.ts
Last active May 28, 2021 19:34
Fix for sync rehydrating zustand store
import {
GetState,
PartialState,
SetState,
State,
StateCreator,
StoreApi,
} from './vanilla'
export const redux = <S extends State, A extends { type: unknown }>(
@barbogast
barbogast / persist.sync.test.tsx
Last active May 27, 2021 20:18
Test for sync storage hydration
import create from '../src/index'
import { persist } from '../src/middleware'
const consoleError = console.error
afterEach(() => {
console.error = consoleError
})
it('can rehydrate state', () => {
let postRehydrationCallbackCallCount = 0