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 AnyFunction = (...args: any) => any | |
type FunctionWithOneArg<T extends AnyFunction> = (args: Record<string, any>) => ReturnType<T> | |
type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | |
type Arguments<T> = [T] extends [(...args: infer U) => any] | |
? U | |
: [T] extends [void] ? [] : [T] | |
type PartialArg<T> = Partial<Arguments<T>[0]> |
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 { transformWhereInput } from './transformWhereInput' | |
test('basic', () => { | |
expect( | |
transformWhereInput({ | |
status: 'ACTIVE', | |
}), | |
).toEqual({ | |
status: { | |
$eq: 'ACTIVE', |
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 deferred<T>() { | |
let resolve: (value: PromiseLike<T> | T) => void; | |
let reject: (reason: Error) => void; | |
let promise = new Promise<T>((_resolve, _reject) => { | |
resolve = _resolve; | |
reject = _reject; | |
}); | |
return { promise, resolve, reject }; | |
} |
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
/* eslint-disable no-underscore-dangle */ | |
module.exports = ({ | |
processEventEmitter, | |
logger, | |
skipRecurringOperationRefetch, | |
}) => | |
class RecurringOperation { | |
constructor({ operation, expiry = null }) { | |
if (typeof operation !== 'function') { |
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
/** | |
* retry async operaration up to N times | |
* | |
* usage: | |
* ```ts | |
* async fn() { | |
* const response = await retry(() => fetch('/endpoint/that/might/fail'), 3) | |
* } | |
* fn() // will retry fetch up to 3 times | |
* ``` |
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 { ApolloClient, createNetworkInterface } from 'react-apollo'; | |
let apolloClient = null; | |
function createClient(headers, userToken) { | |
const networkInterface = createNetworkInterface({ | |
uri: 'https://api.graph.cool/simple/v1/Groopy', | |
opts: { | |
credentials: 'same-origin', | |
// Pass headers here if your graphql server requires them |
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
/ ) | |
/ )__/ )_____/ / | |
( @ . @ ) ) | |
( ) | |
//¨//¨¨//¨// |
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, { PropTypes } from 'react'; | |
function NL2BR({content}) { | |
const strs = content.split('\n'); | |
const {length} = strs; | |
if (length === 1) { | |
return <span>{content}</span>; | |
} |
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 obj = { | |
a: 1, | |
b: 2, | |
c: 3, | |
d: 4, | |
}; | |
const { | |
a, | |
b, |
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 getFrontMatter(file) { | |
return new Promise((resolve, reject) => { | |
readFile(join(__dirname, '../pages', file), (error, content) => { | |
if (error) return reject(error); | |
let doc = fm(content.toString()) | |
resolve(doc); | |
}); | |
}) | |
} |