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
export const usePolling = ({ pollFn, interval }: Params, deps: any[]) => { | |
useEffect(() => { | |
let timeout: number | undefined; | |
let isMounted = true; | |
const poller = async () => { | |
await pollFn(); | |
// only do next polling if the function is still mounted | |
// i.e. it hasn't been replaced by new function because `deps` change |
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 { Action } from 'redux'; | |
import * as plansActions from './plans/actions'; | |
import * as planDetailsActions from './planDetails/actions'; | |
import { reducers } from './reducer'; | |
export type StoreState = Readonly<{ [R in keyof typeof reducers]: ReturnType<typeof reducers[R]> }>; | |
// from object containing { [actionName]: [action] } | |
// then for every action, if the action itself extending AnyAction -> append it to the object | |
// otherwise, if the action is a function and returning AnyAction -> append it to the object |
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 { render, fireEvent, waitForElementToBeRemoved, prettyDOM } from '@testing-library/react'; | |
const { getByText, queryByText } = render( | |
<Component /> | |
); | |
const button = getByText(/Remove [0-9]+ projects? from this migration/); | |
fireEvent.click(button); | |
// click the remove project button |
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 { useCallback } from 'react'; | |
jest.mock('react', () => ({ | |
...require.requireActual('react'), | |
useCallback: jest.fn(), | |
})); | |
const useCallbackSpy = useCallback as jest.Mock<typeof useCallback>; |
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
// Curry is only taking 1 parameter different from partial application | |
curry = fn => { | |
const self = params => arg => { | |
const nextParams = [...params, arg] | |
if (nextParams.length === fn.length) return fn(...nextParams); | |
return self(nextParams); | |
} | |
return self([]) | |
} |
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 convertCallback = (cb, value, status, defaultLetter) => { | |
if (typeof cb === 'function') { | |
cb(value); | |
} else if (typeof cb === 'string' || typeof cb === 'undefined') { | |
const letter = typeof cb === 'string' ? cb : defaultLetter; | |
window[letter] = value; | |
console.log(`request ${status}, stored in variable: ${letter}, below is the value:`); | |
console.log(value); |