Last active
January 15, 2019 17:32
-
-
Save SergProduction/65c1641861d2b506e77c44039fa95c24 to your computer and use it in GitHub Desktop.
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
// @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) |
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
// @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