This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://dev.to/deanius/the-thresholds-of-perception-in-ux-435g | |
export const DURATION = { | |
Frame: 16, | |
Frame60: 16, | |
Frame90: 11, | |
Unison: 10, | |
Chorus: 25, | |
MovieFrame: 42, | |
Echo: 100, | |
Blink: 150, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ObservableInput, Subscription } from 'rxjs'; | |
function useWhileMounted(subsFactory: () => Subscription) { | |
useEffect(() => { | |
const sub = subsFactory(); | |
return () => sub?.unsubscribe(); | |
}, []); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useSubscription(subFactory) { | |
useEffect(() => { | |
const sub = subFactory(); | |
return () => sub.unsubscribe(); | |
}, []); | |
} | |
function CatFetcher() { | |
const [state, dispatch] = useReducer(catReducer, initialState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>DAG of Measurment</title> | |
<link rel="stylesheet" href="https://stackedit.io/style.css" /> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allows us to 'join' (should be memoized so only logs on change of tierId) | |
const SelectedTierFromCache = ({ tierId }) => { | |
return ( | |
<ApolloConsumer> | |
{(client) => { | |
const result = client.readQuery({ query: AVAILABLE_TIERS }); | |
const all = result?.currentTierGroup?.tiers; | |
const selected = all.find((t) => t.tierId === tierId); | |
console.log('Selected tier from cache (do not mutate!)', selected); | |
return null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage | |
// React.memo(Component, sameIgnoringFunctions); | |
// Returns true when all non-function props are the same (===) | |
const isSameIgnoringFunctions = (oldProps, newProps) => | |
Object.keys(oldProps) | |
// filter lets only non-functions through | |
.filter((k) => typeof oldProps[k] !== 'function') | |
// to check if each remaining key is the same in both | |
.every((k) => oldProps[k] === newProps[k]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const singleton = {f1: Promise, f2: Promise} | |
export const FMContext = createContext(singleton); // default value | |
export const useFM = () => { | |
const fm = useContext(FMContext) | |
fm.f1 = somePromise(); | |
return fm | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import "@testing-library/jest-dom"; | |
import { renderHook, act } from "@testing-library/react-hooks"; | |
import { render, fireEvent } from "@testing-library/react"; | |
import { useCounterLogic } from './examples/useCounterLogic'; | |
import { CounterHook } from './examples/CounterHook' | |
describe.only('CounterLogic', () => { | |
describe('increment', () => { | |
it('should change count by 1', () => { |