This file contains hidden or 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 produce, {Draft} from 'immer'; | |
import {useReducer, useMemo} from 'react'; | |
type ActionCreator<State, Payload> = ( | |
payload: Payload | |
) => {type: string; payload: Payload}; | |
type CreatedAction<State, Payload> = ActionCreator<State, Payload> & AnyAction; | |
type Handler<State, Payload> = (state: Draft<State>, payload: Payload) => void; | |
type Handlers<State> = { | |
[actionType: string]: Handler<State, any>; |
This file contains hidden or 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
{ | |
"amount": "0.00", | |
"resptext": "Wrong currency for merch", | |
"cardproc": "NASH", | |
"acctid": "1", | |
"respcode": "32", | |
"defaultacct": "Y", | |
"merchid": "820000000192", | |
"token": "9545666483645454", | |
"respproc": "PPS", |
This file contains hidden or 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
type GuardedResult<ReturnType, DefaultValueType = ReturnType> = ReturnType | DefaultValueType; | |
type GuardedFn<ReturnType, DefaultValueType = ReturnType> = ( | |
...args | |
) => GuardedResult<ReturnType, DefaultValueType>; | |
function guard<ReturnType, DefaultValueType = ReturnType>( | |
fn: GuardedFn<ReturnType, DefaultValueType>, | |
defaultValue: GuardedResult<ReturnType, DefaultValueType> | |
) { | |
const guarded: GuardedFn<ReturnType, DefaultValueType> = (...args) => { |
This file contains hidden or 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
type composeFn<T> = (x: T) => T | Promise<T>; | |
function compose<T>(...fns: composeFn<T>[]) { | |
return async (x: T | Promise<T>): Promise<T> => | |
fns.reduce((v, f) => (async () => f(await v))(), x); | |
} |
This file contains hidden or 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 parse = guard(input => JSON.parse(input), {}); | |
/** | |
* - Will always be an object | |
* - Don't have to clutter with try/catch | |
* - Can test if the returned value is default value to know success | |
* - In development errors are logged to console and browser notifications sent | |
* - In development notifications mesages are cached to not spam developer | |
* - In production, errors are sent to error logging service | |
*/ |
This file contains hidden or 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 usePostMessageHandler = (messageKey, callback) => { | |
useEffect(() => { | |
const receiveMessage = event => { | |
if (event.data === messageKey) { | |
callback(event); | |
} | |
}; | |
window.addEventListener("message", receiveMessage, false); | |
return () => { |
This file contains hidden or 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 e(t, n, r) { | |
function s(o, u) { | |
if (!n[o]) { | |
if (!t[o]) { | |
var a = typeof require == "function" && require; | |
if (!u && a) return a(o, !0); | |
if (i) return i(o, !0); | |
throw new Error("Cannot find module '" + o + "'"); | |
} | |
var f = (n[o] = { exports: {} }); |
This file contains hidden or 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
expect.extend({ | |
toHaveBeenCalledWithSnapshot: received => { | |
expect(received).toHaveBeenCalled(); | |
expect(received.mock.calls).toMatchSnapshot(); | |
return { | |
message: () => '', | |
pass: true, | |
}; | |
}, |
This file contains hidden or 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
class Node { | |
constructor(value){ | |
this.value = value; | |
this.left = null; | |
this.right = null; | |
} | |
insert(value){ | |
if(value < this.value){ | |
if(!this.left){ | |
this.left = new Node(value); |
This file contains hidden or 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, { Component } from "react"; | |
import { Button, Modal } from "semantic-ui-react"; | |
export class Confirm extends Component { | |
state = { open: false }; | |
static defaultProps = { | |
onClose: () => {} | |
}; | |
_handleClose = () => { | |
this.setState({ open: false }); |