- Sync/async generator forms
- Not constant, can be reassigned
- Hoisting can result in runtime exceptions (https://twitter.com/OliverJAsh/status/1247240674388447234)
const head = array => array[0]; | |
const zip = (...arrays) => ( | |
head(arrays).map((value, index) => arrays.map(otherArray => otherArray[index])) | |
); | |
const map = (collection, mapFn) => ( | |
Object.keys(collection).map(key => mapFn(collection[key], key)) | |
); | |
const reduce = (collection, reduceFn, seed) => ( | |
Object.keys(collection).reduce((acc, key) => { | |
const value = collection[key]; |
declare module 'luxon' { | |
namespace luxon { | |
type DateTimeFormat = any; | |
type ZoneOptions = { | |
keepCalendarTime?: boolean; | |
}; | |
type ToFormatOptions = { | |
round: boolean; | |
}; |
const store = configureAndCreateReduxStore(); | |
const { ReduxProvider, ReduxConsumer } = createReactRedux(store); | |
export const FormConnected: React.SFC<OwnProps> = ownProps => ( | |
<ReduxConsumer> | |
{pipe( | |
({ state, dispatch }) => ({ | |
...ownProps, | |
...mapStateToProps(state, ownProps), |
I'm writing demos for my React components, to showcase them in a specific states (e.g. Storybook).
However, the components I'm trying to write demos for are React Redux connected components, and this is making the demos much more difficult to achieve. To illustrate why, I'll start with an example.
Note: the problems I describe here also apply to writing tests (which demos are just one form of).
const tuple = <T extends Array<unknown>>(...args: T): T => args; | |
// `Object.keys` does not return the keys as string literals, only strings. Use this helper as a | |
// workaround. https://github.com/Microsoft/TypeScript/pull/12253#issuecomment-263132208 | |
const keys = <O extends object>(obj: O) => Object.keys(obj) as Array<keyof O>; | |
// `Object.entries` is ES2017, so we must define our own version. | |
const entries = <K extends string, V>(obj: Record<K, V>) => | |
keys(obj).map(key => tuple(key, obj[key])); | |
const fromEntries = <K extends string, V>(arr: Array<[K, V]>) => |
import * as Reader from 'fp-ts/lib/Reader'; | |
import { RouteData } from 'helpers/routes/types'; | |
import { pipe, pipeWith } from 'pipe-ts'; | |
// This will soon be part of fp-ts core | |
// https://github.com/gcanti/fp-ts/issues/904#issuecomment-619346296 | |
const chainW: <Q, A, B>( | |
f: (a: A) => Reader.Reader<Q, B>, | |
) => <R>(ma: Reader.Reader<R, A>) => Reader.Reader<R & Q, B> = Reader.chain as Unrestricted; |
import { from } from 'ix/iterable'; | |
import { map } from 'ix/iterable/operators'; | |
const compare = (a: string, b: string) => | |
from(a).pipe(map((value, index) => value === b[index])); | |
for (const v of compare('yes', 'yas')) { | |
console.log(v); | |
} | |
// true |
describe.only('createDataCron', () => { | |
it( | |
'init', | |
marbles(m => { | |
const source$ = m.cold('--a| '); | |
const sourceS = ' ^------'; | |
const ms = m.time(' ------|'); | |
const expected = ' --a| '; | |
const cron = createDataCron(source$, ms); |
describe.only('createDataCron', () => { | |
it( | |
'init', | |
marbles(m => { | |
const source$ = m.cold('--a| '); | |
const sourceS = ' ^------'; | |
const ms = m.time(' ------|'); | |
const expected = ' --a| '; | |
const cron = createDataCron(source$, ms); |