summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2017-07-27 20:32:45 +0100
committerAndrej Mihajlov <and@mullvad.net>2017-07-27 20:32:45 +0100
commitfd803f74404a1a10f290cbd0852c4ee9a1b2d7ae (patch)
tree0150a4bf94d13ebb6d7507fd2d641a98cff2b489
parentd74e2ea32c5baa3a137359c0bb99cc8727e38c6c (diff)
parente50d99797500b92e9f03d3e243359e300252487f (diff)
downloadmullvadvpn-fd803f74404a1a10f290cbd0852c4ee9a1b2d7ae.tar.xz
mullvadvpn-fd803f74404a1a10f290cbd0852c4ee9a1b2d7ae.zip
Merge branch 'redux-dispatch'
-rw-r--r--app/redux/connection/actions.js4
-rw-r--r--app/redux/store.js16
-rw-r--r--app/routes.js4
-rw-r--r--flow-typed/npm/redux_v3.x.x.js89
4 files changed, 82 insertions, 31 deletions
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index aae63b5506..9f573bede2 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -4,13 +4,13 @@ import { clipboard } from 'electron';
import type { Backend } from '../../lib/backend';
import type { ConnectionReduxState } from './reducers.js';
-import type { ReduxGetStateFn, ReduxDispatchFn } from '../store';
+import type { ReduxGetState, ReduxDispatch } from '../store';
const connect = (backend: Backend, addr: string) => () => backend.connect(addr);
const disconnect = (backend: Backend) => () => backend.disconnect();
const copyIPAddress = () => {
- return (_dispatch: ReduxDispatchFn, getState: ReduxGetStateFn) => {
+ return (_dispatch: ReduxDispatch, getState: ReduxGetState) => {
const ip: ?string = getState().connection.clientIp;
if(ip) {
clipboard.writeText(ip);
diff --git a/app/redux/store.js b/app/redux/store.js
index 76447efc17..93b748ed7a 100644
--- a/app/redux/store.js
+++ b/app/redux/store.js
@@ -10,7 +10,7 @@ import connectionActions from './connection/actions.js';
import settings from './settings/reducers.js';
import settingsActions from './settings/actions.js';
-import type { Store, Dispatch } from 'redux';
+import type { Store } from 'redux';
import type { History } from 'history';
import type { AccountReduxState } from './account/reducers.js';
import type { ConnectionReduxState } from './connection/reducers.js';
@@ -25,14 +25,14 @@ export type ReduxState = {
connection: ConnectionReduxState,
settings: SettingsReduxState
};
-export type ReduxAction = Function
- | LoginChangeAction
- | UpdateSettingsAction
- | ConnectionChangeAction;
-export type ReduxStore = Store<ReduxState, ReduxAction>;
-export type ReduxGetStateFn = () => ReduxState;
-export type ReduxDispatchFn = Dispatch<ReduxAction>;
+export type ReduxAction = LoginChangeAction
+ | UpdateSettingsAction
+ | ConnectionChangeAction;
+export type ReduxStore = Store<ReduxState, ReduxAction, ReduxDispatch>;
+export type ReduxGetState = () => ReduxState;
+export type ReduxDispatch = (action: ReduxAction | ReduxThunk) => any;
+export type ReduxThunk = (dispatch: ReduxDispatch, getState: ReduxGetState) => any;
export default function configureStore(initialState: ?ReduxState, routerHistory: History): ReduxStore {
const router = routerMiddleware(routerHistory);
diff --git a/app/routes.js b/app/routes.js
index 60fb412003..0770785ba4 100644
--- a/app/routes.js
+++ b/app/routes.js
@@ -11,7 +11,7 @@ import AccountPage from './containers/AccountPage';
import SelectLocationPage from './containers/SelectLocationPage';
import { getTransitionProps } from './transitions';
-import type { ReduxGetStateFn } from './redux/store';
+import type { ReduxGetState } from './redux/store';
import type { Backend } from './lib/backend';
export type SharedRouteProps = {
@@ -22,7 +22,7 @@ type CustomRouteProps = {
component: ReactClass<*>
};
-export default function makeRoutes(getState: ReduxGetStateFn, componentProps: SharedRouteProps): React.Element<*> {
+export default function makeRoutes(getState: ReduxGetState, componentProps: SharedRouteProps): React.Element<*> {
// Merge props and render component
const renderMergedProps = (ComponentClass: ReactClass<*>, ...rest: Array<Object>): React.Element<*> => {
diff --git a/flow-typed/npm/redux_v3.x.x.js b/flow-typed/npm/redux_v3.x.x.js
index f4f5e2005b..4f93322f7d 100644
--- a/flow-typed/npm/redux_v3.x.x.js
+++ b/flow-typed/npm/redux_v3.x.x.js
@@ -1,5 +1,6 @@
-// flow-typed signature: 7f1a115f75043c44385071ea3f33c586
-// flow-typed version: 358375125e/redux_v3.x.x/flow_>=v0.33.x
+// This is a custom implementation of redux flow annotations.
+// Please do not overwrite without consideration.
+// PR: https://github.com/flowtype/flow-typed/pull/1071
declare module 'redux' {
@@ -7,19 +8,20 @@ declare module 'redux' {
S = State
A = Action
+ D = Dispatch
*/
declare type Dispatch<A: { type: $Subtype<string> }> = (action: A) => A;
- declare type MiddlewareAPI<S, A> = {
- dispatch: Dispatch<A>;
+ declare type MiddlewareAPI<S, A, D = Dispatch<A>> = {
+ dispatch: D;
getState(): S;
};
- declare type Store<S, A> = {
+ declare type Store<S, A, D = Dispatch<A>> = {
// rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
- dispatch: Dispatch<A>;
+ dispatch: D;
getState(): S;
subscribe(listener: () => void): () => void;
replaceReducer(nextReducer: Reducer<S, A>): void
@@ -29,30 +31,79 @@ declare module 'redux' {
declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;
- declare type Middleware<S, A> =
- (api: MiddlewareAPI<S, A>) =>
- (next: Dispatch<A>) => Dispatch<A>;
+ declare type Middleware<S, A, D = Dispatch<A>> =
+ (api: MiddlewareAPI<S, A, D>) =>
+ (next: D) => D;
- declare type StoreCreator<S, A> = {
- (reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
- (reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
+ declare type StoreCreator<S, A, D = Dispatch<A>> = {
+ (reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
+ (reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
};
- declare type StoreEnhancer<S, A> = (next: StoreCreator<S, A>) => StoreCreator<S, A>;
+ declare type StoreEnhancer<S, A, D = Dispatch<A>> = (next: StoreCreator<S, A, D>) => StoreCreator<S, A, D>;
- declare function createStore<S, A>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
- declare function createStore<S, A>(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
+ declare function createStore<S, A, D>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
+ declare function createStore<S, A, D>(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
- declare function applyMiddleware<S, A>(...middlewares: Array<Middleware<S, A>>): StoreEnhancer<S, A>;
+ declare function applyMiddleware<S, A, D>(...middlewares: Array<Middleware<S, A, D>>): StoreEnhancer<S, A, D>;
declare type ActionCreator<A, B> = (...args: Array<B>) => A;
declare type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> };
- declare function bindActionCreators<A, C: ActionCreator<A, any>>(actionCreator: C, dispatch: Dispatch<A>): C;
- declare function bindActionCreators<A, K, C: ActionCreators<K, A>>(actionCreators: C, dispatch: Dispatch<A>): C;
+ declare function bindActionCreators<A, C: ActionCreator<A, any>, D>(actionCreator: C, dispatch: D): C;
+ declare function bindActionCreators<A, K, C: ActionCreators<K, A>, D>(actionCreators: C, dispatch: D): C;
declare function combineReducers<O: Object, A>(reducers: O): CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
- declare function compose<S, A>(...fns: Array<StoreEnhancer<S, A>>): Function;
+ declare function compose<A, B>(ab: (a: A) => B): (a: A) => B
+ declare function compose<A, B, C>(
+ bc: (b: B) => C,
+ ab: (a: A) => B
+ ): (a: A) => C
+ declare function compose<A, B, C, D>(
+ cd: (c: C) => D,
+ bc: (b: B) => C,
+ ab: (a: A) => B
+ ): (a: A) => D
+ declare function compose<A, B, C, D, E>(
+ de: (d: D) => E,
+ cd: (c: C) => D,
+ bc: (b: B) => C,
+ ab: (a: A) => B
+ ): (a: A) => E
+ declare function compose<A, B, C, D, E, F>(
+ ef: (e: E) => F,
+ de: (d: D) => E,
+ cd: (c: C) => D,
+ bc: (b: B) => C,
+ ab: (a: A) => B
+ ): (a: A) => F
+ declare function compose<A, B, C, D, E, F, G>(
+ fg: (f: F) => G,
+ ef: (e: E) => F,
+ de: (d: D) => E,
+ cd: (c: C) => D,
+ bc: (b: B) => C,
+ ab: (a: A) => B
+ ): (a: A) => G
+ declare function compose<A, B, C, D, E, F, G, H>(
+ gh: (g: G) => H,
+ fg: (f: F) => G,
+ ef: (e: E) => F,
+ de: (d: D) => E,
+ cd: (c: C) => D,
+ bc: (b: B) => C,
+ ab: (a: A) => B
+ ): (a: A) => H
+ declare function compose<A, B, C, D, E, F, G, H, I>(
+ hi: (h: H) => I,
+ gh: (g: G) => H,
+ fg: (f: F) => G,
+ ef: (e: E) => F,
+ de: (d: D) => E,
+ cd: (c: C) => D,
+ bc: (b: B) => C,
+ ab: (a: A) => B
+ ): (a: A) => I
}