mirror of https://github.com/trezor/trezor-wallet
parent
50767c77c3
commit
10ff77a37e
@ -1,41 +1,33 @@
|
||||
/* @flow */
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
|
||||
import * as WalletActions from 'actions/WalletActions';
|
||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
||||
import type { State, Dispatch } from 'flowtype';
|
||||
|
||||
import LanguagePicker from './index';
|
||||
|
||||
type StateProps = {
|
||||
type StateProps = {|
|
||||
language: string,
|
||||
};
|
||||
|};
|
||||
|
||||
type DispatchProps = {
|
||||
type DispatchProps = {|
|
||||
fetchLocale: typeof WalletActions.fetchLocale,
|
||||
};
|
||||
|};
|
||||
|
||||
type OwnProps = {};
|
||||
type OwnProps = {||};
|
||||
|
||||
export type Props = StateProps & DispatchProps;
|
||||
export type Props = {| ...StateProps, ...DispatchProps, ...OwnProps |};
|
||||
|
||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (
|
||||
state: State
|
||||
): StateProps => ({
|
||||
const mapStateToProps = (state: State): StateProps => ({
|
||||
language: state.wallet.language,
|
||||
});
|
||||
|
||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (
|
||||
dispatch: Dispatch
|
||||
): DispatchProps => ({
|
||||
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
|
||||
fetchLocale: bindActionCreators(WalletActions.fetchLocale, dispatch),
|
||||
});
|
||||
|
||||
export default withRouter(
|
||||
connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(LanguagePicker)
|
||||
);
|
||||
export default connect<Props, OwnProps, StateProps, DispatchProps, State, Dispatch>(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(LanguagePicker);
|
||||
|
@ -0,0 +1,259 @@
|
||||
/**
|
||||
* Original implementation of this file by @marudor at https://github.com/marudor/flowInterfaces
|
||||
* Copied here based on intention to merge with flow-typed expressed here:
|
||||
* https://github.com/marudor/flowInterfaces/issues/6
|
||||
*/
|
||||
// Mostly from https://github.com/yahoo/react-intl/wiki/API#react-intl-api
|
||||
declare module "react-intl" {
|
||||
import type { Element, ChildrenArray } from "react";
|
||||
|
||||
declare type $npm$ReactIntl$LocaleData = {
|
||||
locale: string,
|
||||
[key: string]: any
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$MessageDescriptor = {
|
||||
id: string,
|
||||
description?: string,
|
||||
defaultMessage?: string
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$IntlConfig = {
|
||||
locale: string,
|
||||
formats: Object,
|
||||
messages: { [id: string]: string },
|
||||
|
||||
defaultLocale?: string,
|
||||
defaultFormats?: Object
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$IntlProviderConfig = {
|
||||
locale?: string,
|
||||
formats?: Object,
|
||||
messages?: { [id: string]: string },
|
||||
|
||||
defaultLocale?: string,
|
||||
defaultFormats?: Object
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$IntlFormat = {
|
||||
formatDate: (value: any, options?: Object) => string,
|
||||
formatTime: (value: any, options?: Object) => string,
|
||||
formatRelative: (value: any, options?: Object) => string,
|
||||
formatNumber: (value: any, options?: Object) => string,
|
||||
formatPlural: (value: any, options?: Object) => string,
|
||||
formatMessage: (
|
||||
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||
values?: Object
|
||||
) => string,
|
||||
formatHTMLMessage: (
|
||||
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||
values?: Object
|
||||
) => string
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$IntlShape = $npm$ReactIntl$IntlConfig &
|
||||
$npm$ReactIntl$IntlFormat & { now: () => number };
|
||||
|
||||
declare type $npm$ReactIntl$DateTimeFormatOptions = {
|
||||
localeMatcher?: "best fit" | "lookup",
|
||||
formatMatcher?: "basic" | "best fit",
|
||||
|
||||
timeZone?: string,
|
||||
hour12?: boolean,
|
||||
|
||||
weekday?: "narrow" | "short" | "long",
|
||||
era?: "narrow" | "short" | "long",
|
||||
year?: "numeric" | "2-digit",
|
||||
month?: "numeric" | "2-digit" | "narrow" | "short" | "long",
|
||||
day?: "numeric" | "2-digit",
|
||||
hour?: "numeric" | "2-digit",
|
||||
minute?: "numeric" | "2-digit",
|
||||
second?: "numeric" | "2-digit",
|
||||
timeZoneName?: "short" | "long"
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$RelativeFormatOptions = {
|
||||
style?: "best fit" | "numeric",
|
||||
units?: "second" | "minute" | "hour" | "day" | "month" | "year"
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$NumberFormatOptions = {
|
||||
localeMatcher?: "best fit" | "lookup",
|
||||
|
||||
style?: "decimal" | "currency" | "percent",
|
||||
|
||||
currency?: string,
|
||||
currencyDisplay?: "symbol" | "code" | "name",
|
||||
|
||||
useGrouping?: boolean,
|
||||
|
||||
minimumIntegerDigits?: number,
|
||||
minimumFractionDigits?: number,
|
||||
maximumFractionDigits?: number,
|
||||
minimumSignificantDigits?: number,
|
||||
maximumSignificantDigits?: number
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$PluralFormatOptions = {
|
||||
style?: "cardinal" | "ordinal"
|
||||
};
|
||||
|
||||
declare type $npm$ReactIntl$PluralCategoryString =
|
||||
| "zero"
|
||||
| "one"
|
||||
| "two"
|
||||
| "few"
|
||||
| "many"
|
||||
| "other";
|
||||
|
||||
declare type $npm$ReactIntl$DateParseable = number | string | Date;
|
||||
// PropType checker
|
||||
declare function intlShape(
|
||||
props: Object,
|
||||
propName: string,
|
||||
componentName: string
|
||||
): void;
|
||||
declare function addLocaleData(
|
||||
data: $npm$ReactIntl$LocaleData | Array<$npm$ReactIntl$LocaleData>
|
||||
): void;
|
||||
declare function defineMessages<
|
||||
T: { [key: string]: $Exact<$npm$ReactIntl$MessageDescriptor> }
|
||||
>(
|
||||
messageDescriptors: T
|
||||
): T;
|
||||
|
||||
declare type InjectIntlProvidedProps = {
|
||||
intl: $npm$ReactIntl$IntlShape
|
||||
}
|
||||
|
||||
declare type InjectIntlVoidProps = {
|
||||
intl: $npm$ReactIntl$IntlShape | void
|
||||
}
|
||||
|
||||
declare type ComponentWithDefaultProps<DefaultProps: {}, Props: {}> =
|
||||
| React$ComponentType<Props>
|
||||
| React$StatelessFunctionalComponent<Props>
|
||||
| ChildrenArray<void | null | boolean | string | number | Element<any>>;
|
||||
|
||||
declare type InjectIntlOptions = {
|
||||
intlPropName?: string,
|
||||
withRef?: boolean
|
||||
}
|
||||
|
||||
declare class IntlInjectedComponent<TOwnProps, TDefaultProps> extends React$Component<TOwnProps> {
|
||||
static WrappedComponent: Class<React$Component<TOwnProps & InjectIntlProvidedProps>>,
|
||||
static defaultProps: TDefaultProps,
|
||||
props: TOwnProps
|
||||
}
|
||||
|
||||
declare type IntlInjectedComponentClass<TOwnProps, TDefaultProps: {} = {}> = Class<
|
||||
IntlInjectedComponent<TOwnProps, TDefaultProps>
|
||||
>;
|
||||
|
||||
declare function injectIntl<P: {}, Component: React$ComponentType<P>>(
|
||||
WrappedComponent: Component,
|
||||
options?: InjectIntlOptions,
|
||||
): React$ComponentType<
|
||||
$Diff<React$ElementConfig<Component>, InjectIntlVoidProps>
|
||||
>;
|
||||
|
||||
declare function formatMessage(
|
||||
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||
values?: Object
|
||||
): string;
|
||||
declare function formatHTMLMessage(
|
||||
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||
values?: Object
|
||||
): string;
|
||||
declare function formatDate(
|
||||
value: any,
|
||||
options?: $npm$ReactIntl$DateTimeFormatOptions & { format: string }
|
||||
): string;
|
||||
declare function formatTime(
|
||||
value: any,
|
||||
options?: $npm$ReactIntl$DateTimeFormatOptions & { format: string }
|
||||
): string;
|
||||
declare function formatRelative(
|
||||
value: any,
|
||||
options?: $npm$ReactIntl$RelativeFormatOptions & {
|
||||
format: string,
|
||||
now: any
|
||||
}
|
||||
): string;
|
||||
declare function formatNumber(
|
||||
value: any,
|
||||
options?: $npm$ReactIntl$NumberFormatOptions & { format: string }
|
||||
): string;
|
||||
declare function formatPlural(
|
||||
value: any,
|
||||
options?: $npm$ReactIntl$PluralFormatOptions
|
||||
): $npm$ReactIntl$PluralCategoryString;
|
||||
|
||||
declare class FormattedMessage extends React$Component<
|
||||
$npm$ReactIntl$MessageDescriptor & {
|
||||
values?: Object,
|
||||
tagName?: string,
|
||||
children?:
|
||||
| ((...formattedMessage: Array<React$Node>) => React$Node)
|
||||
| (string => React$Node)
|
||||
}
|
||||
> {}
|
||||
declare class FormattedHTMLMessage extends React$Component<
|
||||
$npm$ReactIntl$DateTimeFormatOptions & {
|
||||
values?: Object,
|
||||
tagName?: string,
|
||||
children?: (...formattedMessage: Array<React$Node>) => React$Node
|
||||
}
|
||||
> {}
|
||||
declare class FormattedDate extends React$Component<
|
||||
$npm$ReactIntl$DateTimeFormatOptions & {
|
||||
value: $npm$ReactIntl$DateParseable,
|
||||
format?: string,
|
||||
children?: (formattedDate: string) => React$Node
|
||||
}
|
||||
> {}
|
||||
declare class FormattedTime extends React$Component<
|
||||
$npm$ReactIntl$DateTimeFormatOptions & {
|
||||
value: $npm$ReactIntl$DateParseable,
|
||||
format?: string,
|
||||
children?: (formattedDate: string) => React$Node
|
||||
}
|
||||
> {}
|
||||
declare class FormattedRelative extends React$Component<
|
||||
$npm$ReactIntl$RelativeFormatOptions & {
|
||||
value: $npm$ReactIntl$DateParseable,
|
||||
format?: string,
|
||||
updateInterval?: number,
|
||||
initialNow?: $npm$ReactIntl$DateParseable,
|
||||
children?: (formattedDate: string) => React$Node
|
||||
}
|
||||
> {}
|
||||
declare class FormattedNumber extends React$Component<
|
||||
$npm$ReactIntl$NumberFormatOptions & {
|
||||
value: number | string,
|
||||
format?: string,
|
||||
children?: (formattedNumber: string) => React$Node
|
||||
}
|
||||
> {}
|
||||
declare class FormattedPlural extends React$Component<
|
||||
$npm$ReactIntl$PluralFormatOptions & {
|
||||
value: number | string,
|
||||
other: React$Node,
|
||||
zero?: React$Node,
|
||||
one?: React$Node,
|
||||
two?: React$Node,
|
||||
few?: React$Node,
|
||||
many?: React$Node,
|
||||
children?: (formattedPlural: React$Node) => React$Node
|
||||
}
|
||||
> {}
|
||||
declare class IntlProvider extends React$Component<
|
||||
$npm$ReactIntl$IntlProviderConfig & {
|
||||
children?: React$Node,
|
||||
initialNow?: $npm$ReactIntl$DateParseable
|
||||
}
|
||||
> {}
|
||||
declare type IntlShape = $npm$ReactIntl$IntlShape;
|
||||
declare type MessageDescriptor = $npm$ReactIntl$MessageDescriptor;
|
||||
}
|
@ -1,127 +1,275 @@
|
||||
// flow-typed signature: 59b0c4be0e1408f21e2446be96c79804
|
||||
// flow-typed version: 9092387fd2/react-redux_v5.x.x/flow_>=v0.54.x
|
||||
/**
|
||||
The order of type arguments for connect() is as follows:
|
||||
|
||||
import type { Dispatch, Store } from 'redux';
|
||||
connect<Props, OwnProps, StateProps, DispatchProps, State, Dispatch>(…)
|
||||
|
||||
declare module 'react-redux' {
|
||||
/*
|
||||
In Flow v0.89 only the first two are mandatory to specify. Other 4 can be repaced with the new awesome type placeholder:
|
||||
|
||||
S = State
|
||||
A = Action
|
||||
D = Dispatch
|
||||
OP = OwnProps
|
||||
SP = StateProps
|
||||
DP = DispatchProps
|
||||
connect<Props, OwnProps, _, _, _, _>(…)
|
||||
|
||||
*/
|
||||
But beware, in case of weird type errors somewhere in random places
|
||||
just type everything and get to a green field and only then try to
|
||||
remove the definitions you see bogus.
|
||||
|
||||
declare type MapStateToProps<S, OP: Object, SP: Object> = (
|
||||
state: S,
|
||||
ownProps: OP
|
||||
) => ((state: S, ownProps: OP) => SP) | SP;
|
||||
Decrypting the abbreviations:
|
||||
WC = Component being wrapped
|
||||
S = State
|
||||
D = Dispatch
|
||||
OP = OwnProps
|
||||
SP = StateProps
|
||||
DP = DispatchProps
|
||||
MP = Merge props
|
||||
RSP = Returned state props
|
||||
RDP = Returned dispatch props
|
||||
RMP = Returned merge props
|
||||
CP = Props for returned component
|
||||
Com = React Component
|
||||
ST = Static properties of Com
|
||||
EFO = Extra factory options (used only in connectAdvanced)
|
||||
*/
|
||||
|
||||
declare module "react-redux" {
|
||||
// ------------------------------------------------------------
|
||||
// Typings for connect()
|
||||
// ------------------------------------------------------------
|
||||
|
||||
declare export type Options<S, OP, SP, MP> = {|
|
||||
pure?: boolean,
|
||||
withRef?: boolean,
|
||||
areStatesEqual?: (next: S, prev: S) => boolean,
|
||||
areOwnPropsEqual?: (next: OP, prev: OP) => boolean,
|
||||
areStatePropsEqual?: (next: SP, prev: SP) => boolean,
|
||||
areMergedPropsEqual?: (next: MP, prev: MP) => boolean,
|
||||
storeKey?: string,
|
||||
|};
|
||||
|
||||
declare type MapDispatchToProps<D, OP: Object, DP: Object> =
|
||||
declare type MapStateToProps<-S, -OP, +SP> =
|
||||
| ((state: S, ownProps: OP) => SP)
|
||||
// If you want to use the factory function but get a strange error
|
||||
// like "function is not an object" then just type the factory function
|
||||
// like this:
|
||||
// const factory: (State, OwnProps) => (State, OwnProps) => StateProps
|
||||
// and provide the StateProps type to the SP type parameter.
|
||||
| ((state: S, ownProps: OP) => (state: S, ownProps: OP) => SP);
|
||||
|
||||
declare type Bind<D> = <A, R>((...A) => R) => (...A) => $Call<D, R>;
|
||||
|
||||
declare type MapDispatchToPropsFn<D, -OP, +DP> =
|
||||
| ((dispatch: D, ownProps: OP) => DP)
|
||||
| DP;
|
||||
// If you want to use the factory function but get a strange error
|
||||
// like "function is not an object" then just type the factory function
|
||||
// like this:
|
||||
// const factory: (Dispatch, OwnProps) => (Dispatch, OwnProps) => DispatchProps
|
||||
// and provide the DispatchProps type to the DP type parameter.
|
||||
| ((dispatch: D, ownProps: OP) => (dispatch: D, ownProps: OP) => DP);
|
||||
|
||||
declare class ConnectedComponent<OP, +WC> extends React$Component<OP> {
|
||||
static +WrappedComponent: WC;
|
||||
getWrappedInstance(): React$ElementRef<WC>;
|
||||
}
|
||||
declare type Connector<P, OP, MP: P> = <WC: React$ComponentType<P>>(
|
||||
WC,
|
||||
) => Class<ConnectedComponent<OP, WC>> & WC;
|
||||
|
||||
// No `mergeProps` argument
|
||||
|
||||
declare export function connect<-P, -OP, -SP, -DP, -S, -D>(
|
||||
mapStateToProps?: null | void,
|
||||
mapDispatchToProps?: null | void,
|
||||
mergeProps?: null | void,
|
||||
options?: ?Options<S, OP, {||}, {| ...OP, dispatch: D |}>,
|
||||
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||
// Just make your OP parameter an exact object.
|
||||
): Connector<P, OP, {| ...OP, dispatch: D |}>;
|
||||
|
||||
declare export function connect<-P, -OP, -SP, -DP, -S, -D>(
|
||||
// If you get error here try adding return type to your mapStateToProps function
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps?: null | void,
|
||||
mergeProps?: null | void,
|
||||
options?: ?Options<S, OP, SP, {| ...OP, ...SP |}>,
|
||||
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||
// Just make your OP parameter an exact object.
|
||||
): Connector<P, OP, {| ...OP, ...SP |}>;
|
||||
|
||||
// In this case DP is an object of functions which has been bound to dispatch
|
||||
// by the given mapDispatchToProps function.
|
||||
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||
mapStateToProps: null | void,
|
||||
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||
mergeProps?: null | void,
|
||||
options?: ?Options<S, OP, {||}, {| ...OP, ...DP |}>,
|
||||
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||
// Just make your OP parameter an exact object.
|
||||
): Connector<P, OP, {| ...OP, ...DP |}>;
|
||||
|
||||
// In this case DP is an object of action creators not yet bound to dispatch,
|
||||
// this difference is not important in the vanila redux,
|
||||
// but in case of usage with redux-thunk, the return type may differ.
|
||||
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||
mapStateToProps: null | void,
|
||||
mapDispatchToProps: DP,
|
||||
mergeProps?: null | void,
|
||||
options?: ?Options<S, OP, {||}, {| ...OP, ...DP |}>,
|
||||
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||
// Just make your OP parameter an exact object.
|
||||
): Connector<P, OP, {| ...OP, ...$ObjMap<DP, Bind<D>> |}>;
|
||||
|
||||
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||
// If you get error here try adding return type to your mapStateToProps function
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||
mergeProps?: null | void,
|
||||
options?: ?Options<S, OP, SP, {| ...OP, ...SP, ...DP |}>,
|
||||
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||
// Just make your OP parameter an exact object.
|
||||
): Connector<P, OP, {| ...OP, ...SP, ...DP |}>;
|
||||
|
||||
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||
// If you get error here try adding return type to your mapStateToProps function
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: DP,
|
||||
mergeProps?: null | void,
|
||||
options?: ?Options<S, OP, SP, {| ...OP, ...SP, ...DP |}>,
|
||||
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||
// Just make your OP parameter an exact object.
|
||||
): Connector<P, OP, {| ...OP, ...SP, ...$ObjMap<DP, Bind<D>> |}>;
|
||||
|
||||
// With `mergeProps` argument
|
||||
|
||||
declare type MergeProps<SP, DP: Object, OP: Object, P: Object> = (
|
||||
declare type MergeProps<+P, -OP, -SP, -DP> = (
|
||||
stateProps: SP,
|
||||
dispatchProps: DP,
|
||||
ownProps: OP
|
||||
ownProps: OP,
|
||||
) => P;
|
||||
|
||||
declare type Context = { store: Store<*, *> };
|
||||
declare export function connect<-P, -OP, -SP: {||}, -DP: {||}, S, D>(
|
||||
mapStateToProps: null | void,
|
||||
mapDispatchToProps: null | void,
|
||||
// If you get error here try adding return type to you mapStateToProps function
|
||||
mergeProps: MergeProps<P, OP, {||}, {| dispatch: D |}>,
|
||||
options?: ?Options<S, OP, {||}, P>,
|
||||
): Connector<P, OP, P>;
|
||||
|
||||
declare type ComponentWithDefaultProps<DP: {}, P: {}, CP: P> = Class<React$Component<CP>> & { defaultProps: DP };
|
||||
declare export function connect<-P, -OP, -SP, -DP: {||}, S, D>(
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: null | void,
|
||||
// If you get error here try adding return type to you mapStateToProps function
|
||||
mergeProps: MergeProps<P, OP, SP, {| dispatch: D |}>,
|
||||
options?: ?Options<S, OP, SP, P>,
|
||||
): Connector<P, OP, P>;
|
||||
|
||||
declare class ConnectedComponentWithDefaultProps<
|
||||
OP,
|
||||
DP,
|
||||
CP
|
||||
> extends React$Component<OP> {
|
||||
static defaultProps: DP, // <= workaround for https://github.com/facebook/flow/issues/4644
|
||||
static WrappedComponent: Class<React$Component<CP>>,
|
||||
getWrappedInstance(): React$Component<CP>,
|
||||
props: OP,
|
||||
state: void
|
||||
}
|
||||
// In this case DP is an object of functions which has been bound to dispatch
|
||||
// by the given mapDispatchToProps function.
|
||||
declare export function connect<-P, -OP, -SP: {||}, -DP, S, D>(
|
||||
mapStateToProps: null | void,
|
||||
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||
mergeProps: MergeProps<P, OP, {||}, DP>,
|
||||
options?: ?Options<S, OP, {||}, P>,
|
||||
): Connector<P, OP, P>;
|
||||
|
||||
declare class ConnectedComponent<OP, P> extends React$Component<OP> {
|
||||
static WrappedComponent: Class<React$Component<P>>,
|
||||
getWrappedInstance(): React$Component<P>,
|
||||
props: OP,
|
||||
state: void
|
||||
}
|
||||
// In this case DP is an object of action creators not yet bound to dispatch,
|
||||
// this difference is not important in the vanila redux,
|
||||
// but in case of usage with redux-thunk, the return type may differ.
|
||||
declare export function connect<-P, -OP, -SP: {||}, -DP, S, D>(
|
||||
mapStateToProps: null | void,
|
||||
mapDispatchToProps: DP,
|
||||
mergeProps: MergeProps<P, OP, {||}, $ObjMap<DP, Bind<D>>>,
|
||||
options?: ?Options<S, OP, {||}, P>,
|
||||
): Connector<P, OP, P>;
|
||||
|
||||
declare type ConnectedComponentWithDefaultPropsClass<OP, DP, CP> = Class<ConnectedComponentWithDefaultProps<OP, DP, CP>>;
|
||||
// In this case DP is an object of functions which has been bound to dispatch
|
||||
// by the given mapDispatchToProps function.
|
||||
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||
mergeProps: MergeProps<P, OP, SP, DP>,
|
||||
options?: ?Options<S, OP, SP, P>,
|
||||
): Connector<P, OP, P>;
|
||||
|
||||
declare type ConnectedComponentClass<OP, P> = Class<ConnectedComponent<OP, P>>;
|
||||
// In this case DP is an object of action creators not yet bound to dispatch,
|
||||
// this difference is not important in the vanila redux,
|
||||
// but in case of usage with redux-thunk, the return type may differ.
|
||||
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: DP,
|
||||
mergeProps: MergeProps<P, OP, SP, $ObjMap<DP, Bind<D>>>,
|
||||
options?: ?Options<S, OP, SP, P>,
|
||||
): Connector<P, OP, P>;
|
||||
|
||||
declare type Connector<OP, P> = (<DP: {}, CP: {}>(
|
||||
component: ComponentWithDefaultProps<DP, P, CP>
|
||||
) => ConnectedComponentWithDefaultPropsClass<OP, DP, CP>) &
|
||||
((component: React$ComponentType<P>) => ConnectedComponentClass<OP, P>);
|
||||
// ------------------------------------------------------------
|
||||
// Typings for Provider
|
||||
// ------------------------------------------------------------
|
||||
|
||||
declare class Provider<S, A> extends React$Component<{
|
||||
store: Store<S, A>,
|
||||
children?: any
|
||||
declare export class Provider<Store> extends React$Component<{
|
||||
store: Store,
|
||||
children?: React$Node,
|
||||
}> {}
|
||||
|
||||
declare function createProvider(
|
||||
declare export function createProvider(
|
||||
storeKey?: string,
|
||||
subKey?: string
|
||||
): Provider<*, *>;
|
||||
subKey?: string,
|
||||
): Class<Provider<*>>;
|
||||
|
||||
declare type ConnectOptions = {
|
||||
pure?: boolean,
|
||||
withRef?: boolean
|
||||
};
|
||||
// ------------------------------------------------------------
|
||||
// Typings for connectAdvanced()
|
||||
// ------------------------------------------------------------
|
||||
|
||||
declare type Null = null | void;
|
||||
declare type ConnectAdvancedOptions = {
|
||||
getDisplayName?: (name: string) => string,
|
||||
methodName?: string,
|
||||
renderCountProp?: string,
|
||||
shouldHandleStateChanges?: boolean,
|
||||
storeKey?: string,
|
||||
withRef?: boolean,
|
||||
};
|
||||
|
||||
declare function connect<A, OP>(
|
||||
...rest: Array<void> // <= workaround for https://github.com/facebook/flow/issues/2360
|
||||
): Connector<OP, $Supertype<{ dispatch: Dispatch<A> } & OP>>;
|
||||
declare type SelectorFactoryOptions<Com> = {
|
||||
getDisplayName: (name: string) => string,
|
||||
methodName: string,
|
||||
renderCountProp: ?string,
|
||||
shouldHandleStateChanges: boolean,
|
||||
storeKey: string,
|
||||
withRef: boolean,
|
||||
displayName: string,
|
||||
wrappedComponentName: string,
|
||||
WrappedComponent: Com,
|
||||
};
|
||||
|
||||
declare function connect<A, OP>(
|
||||
mapStateToProps: Null,
|
||||
mapDispatchToProps: Null,
|
||||
mergeProps: Null,
|
||||
options: ConnectOptions
|
||||
): Connector<OP, $Supertype<{ dispatch: Dispatch<A> } & OP>>;
|
||||
declare type MapStateToPropsEx<S: Object, SP: Object, RSP: Object> = (
|
||||
state: S,
|
||||
props: SP,
|
||||
) => RSP;
|
||||
|
||||
declare function connect<S, A, OP, SP>(
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: Null,
|
||||
mergeProps: Null,
|
||||
options?: ConnectOptions
|
||||
): Connector<OP, $Supertype<SP & { dispatch: Dispatch<A> } & OP>>;
|
||||
|
||||
declare function connect<A, OP, DP>(
|
||||
mapStateToProps: Null,
|
||||
mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
|
||||
mergeProps: Null,
|
||||
options?: ConnectOptions
|
||||
): Connector<OP, $Supertype<DP & OP>>;
|
||||
|
||||
declare function connect<S, A, OP, SP, DP>(
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
|
||||
mergeProps: Null,
|
||||
options?: ConnectOptions
|
||||
): Connector<OP, $Supertype<SP & DP & OP>>;
|
||||
declare type SelectorFactory<
|
||||
Com: React$ComponentType<*>,
|
||||
Dispatch,
|
||||
S: Object,
|
||||
OP: Object,
|
||||
EFO: Object,
|
||||
CP: Object,
|
||||
> = (
|
||||
dispatch: Dispatch,
|
||||
factoryOptions: SelectorFactoryOptions<Com> & EFO,
|
||||
) => MapStateToPropsEx<S, OP, CP>;
|
||||
|
||||
declare function connect<S, A, OP, SP, DP, P>(
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: Null,
|
||||
mergeProps: MergeProps<SP, DP, OP, P>,
|
||||
options?: ConnectOptions
|
||||
): Connector<OP, P>;
|
||||
declare export function connectAdvanced<
|
||||
Com: React$ComponentType<*>,
|
||||
D,
|
||||
S: Object,
|
||||
OP: Object,
|
||||
CP: Object,
|
||||
EFO: Object,
|
||||
ST: { [_: $Keys<Com>]: any },
|
||||
>(
|
||||
selectorFactory: SelectorFactory<Com, D, S, OP, EFO, CP>,
|
||||
connectAdvancedOptions: ?(ConnectAdvancedOptions & EFO),
|
||||
): (component: Com) => React$ComponentType<OP> & $Shape<ST>;
|
||||
|
||||
declare function connect<S, A, OP, SP, DP, P>(
|
||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||
mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
|
||||
mergeProps: MergeProps<SP, DP, OP, P>,
|
||||
options?: ConnectOptions
|
||||
): Connector<OP, P>;
|
||||
declare export default {
|
||||
Provider: typeof Provider,
|
||||
createProvider: typeof createProvider,
|
||||
connect: typeof connect,
|
||||
connectAdvanced: typeof connectAdvanced,
|
||||
};
|
||||
}
|
@ -1,26 +1,20 @@
|
||||
/* @flow */
|
||||
import { connect } from 'react-redux';
|
||||
import type { MapStateToProps } from 'react-redux';
|
||||
import type { State } from 'flowtype';
|
||||
import type { State, Dispatch } from 'flowtype';
|
||||
import Dashboard from './index';
|
||||
|
||||
type OwnProps = {};
|
||||
type OwnProps = {||};
|
||||
|
||||
type StateProps = {
|
||||
type StateProps = {|
|
||||
localStorage: $ElementType<State, 'localStorage'>,
|
||||
wallet: $ElementType<State, 'wallet'>,
|
||||
};
|
||||
|};
|
||||
|
||||
export type Props = StateProps;
|
||||
export type Props = {| ...StateProps |};
|
||||
|
||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (
|
||||
state: State
|
||||
): StateProps => ({
|
||||
const mapStateToProps = (state: State): StateProps => ({
|
||||
localStorage: state.localStorage,
|
||||
wallet: state.wallet,
|
||||
});
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
null
|
||||
)(Dashboard);
|
||||
export default connect<Props, OwnProps, StateProps, _, State, Dispatch>(mapStateToProps)(Dashboard);
|
||||
|
Loading…
Reference in new issue