Skip to content

Instantly share code, notes, and snippets.

@SergProduction
Last active January 15, 2019 17:32
Show Gist options
  • Save SergProduction/65c1641861d2b506e77c44039fa95c24 to your computer and use it in GitHub Desktop.
Save SergProduction/65c1641861d2b506e77c44039fa95c24 to your computer and use it in GitHub Desktop.
// @flow
type F = <P, D, R>(P => (D => R)) => (P => R)
type BindActions<O: {[key: string]: Function}> = $ObjMap<O, F>
type Dispatch = string
const actionFoo = (a: number) => (d: Dispatch): Promise<number> => Promise.resolve(a)
const actionBar = (a: string) => (d: Dispatch): Promise<Array<string>> => Promise.resolve([a])
type MapDispatchToProps = BindActions<{
actionFoo: typeof actionFoo,
actionBar: typeof actionBar,
}>
type OtherProps = {a: string}
type Props = {|
...$Exact<MapDispatchToProps>,
...$Exact<OtherProps>
|}
const StatelessFunctionalComponents = (props: Props) => {
props.actionFoo(7)
.then(x => x + 5) // Works!
props.actionBar('7')
.then(x => x.concat('5') // Works!
}
connect(
null,
{
actionFoo,
actionBar
}
)(StatelessFunctionalComponents)
// @flow
type F = <P, D, R>(P => (D => R)) => (P => R)
type BindActions<O: {[key: string]: Function}> = $ObjMap<O, F>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment