diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-06-19 19:29:02 +0300 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-06-22 16:13:54 +0300 |
| commit | 62d401bdbab5c32c7352a81658a7e488a8b8ca78 (patch) | |
| tree | 76cce502c68a9335c8736e5d0e13f44e3e77ebd3 | |
| parent | db640da0fe748b7255f7b72fbd70459c55c5120d (diff) | |
| download | mullvadvpn-62d401bdbab5c32c7352a81658a7e488a8b8ca78.tar.xz mullvadvpn-62d401bdbab5c32c7352a81658a7e488a8b8ca78.zip | |
Add flow annotations for redux actions
| -rw-r--r-- | app/actions/connect.js | 21 | ||||
| -rw-r--r-- | app/actions/settings.js | 8 | ||||
| -rw-r--r-- | app/actions/user.js | 13 | ||||
| -rw-r--r-- | app/store.js | 2 |
4 files changed, 28 insertions, 16 deletions
diff --git a/app/actions/connect.js b/app/actions/connect.js index a63496661a..11e88e99b0 100644 --- a/app/actions/connect.js +++ b/app/actions/connect.js @@ -1,20 +1,19 @@ import { clipboard } from 'electron'; import { createAction } from 'redux-actions'; -/** Action for changing connection state */ -const connectionChange = createAction('CONNECTION_CHANGE'); +import type { Backend } from '../lib/backend'; +import type { ConnectReduxState } from '../reducers/connect'; +import type { ReduxAction, ReduxGetStateFn, ReduxDispatchFn } from '../store'; -/** Action for connecting to server */ -const connect = (backend, addr) => () => backend.connect(addr); +export type ConnectionChangeAction = <T: $Shape<ConnectReduxState>>(state: T) => ReduxAction<T>; -/** Action for disconnecting from server */ -const disconnect = (backend) => () => backend.disconnect(); - -/** Action for copying IP address in memory */ +const connectionChange: ConnectionChangeAction = createAction('CONNECTION_CHANGE'); +const connect = (backend: Backend, addr: string) => () => backend.connect(addr); +const disconnect = (backend: Backend) => () => backend.disconnect(); const copyIPAddress = () => { - return (_, getState) => { - const ip = getState().connect.clientIp; - if(typeof(ip) === 'string') { + return (_dispatch: ReduxDispatchFn, getState: ReduxGetStateFn) => { + const ip: ?string = getState().connect.clientIp; + if(ip) { clipboard.writeText(ip); } }; diff --git a/app/actions/settings.js b/app/actions/settings.js index 7a482a578f..4788a88f85 100644 --- a/app/actions/settings.js +++ b/app/actions/settings.js @@ -1,5 +1,11 @@ +// @flow import { createAction } from 'redux-actions'; -const updateSettings = createAction('SETTINGS_UPDATE'); +import type { SettingsReduxState } from '../reducers/settings'; +import type { ReduxAction } from '../store'; + +export type UpdateSettingsAction = <T: $Shape<SettingsReduxState>>(state: T) => ReduxAction<T>; + +const updateSettings: UpdateSettingsAction = createAction('SETTINGS_UPDATE'); export default { updateSettings }; diff --git a/app/actions/user.js b/app/actions/user.js index c1519ba19b..1b4d46ad2d 100644 --- a/app/actions/user.js +++ b/app/actions/user.js @@ -1,7 +1,14 @@ +// @flow import { createAction } from 'redux-actions'; -const loginChange = createAction('USER_LOGIN_CHANGE'); -const login = (backend, account) => () => backend.login(account); -const logout = (backend) => () => backend.logout(); +import type { Backend } from '../lib/backend'; +import type { UserReduxState } from '../reducers/user'; +import type { ReduxAction } from '../store'; + +export type LoginChangeAction = <T: $Shape<UserReduxState>>(state: T) => ReduxAction<T>; + +const loginChange: LoginChangeAction = createAction('USER_LOGIN_CHANGE'); +const login = (backend: Backend, account: string) => () => backend.login(account); +const logout = (backend: Backend) => () => backend.logout(); export default { login, logout, loginChange }; diff --git a/app/store.js b/app/store.js index 667f03b5a3..83f7ff5430 100644 --- a/app/store.js +++ b/app/store.js @@ -29,7 +29,7 @@ export type ReduxDispatchFn<T: *> = Dispatch<ReduxAction<T>>; export default function configureStore(initialState: ?ReduxState, routerHistory: History): ReduxStore { const router = routerMiddleware(routerHistory); - const actionCreators: { string: Function } = { + const actionCreators: { [string]: Function } = { ...userActions, ...connectActions, ...settingsActions, |
