diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-06-01 16:13:10 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-06-05 12:11:55 +0200 |
| commit | ca2f6fbfcad7b73d4ea63ef46cb1cab943ec9087 (patch) | |
| tree | b1f7754eb50896ab3681e35fa4e08be642b940c9 /app/redux | |
| parent | 5852c980980de53e00d76a0bdb4b41bf5c0f5b39 (diff) | |
| download | mullvadvpn-ca2f6fbfcad7b73d4ea63ef46cb1cab943ec9087.tar.xz mullvadvpn-ca2f6fbfcad7b73d4ea63ef46cb1cab943ec9087.zip | |
Add formatted source code
Diffstat (limited to 'app/redux')
| -rw-r--r-- | app/redux/account/actions.js | 15 | ||||
| -rw-r--r-- | app/redux/account/reducers.js | 107 | ||||
| -rw-r--r-- | app/redux/connection/actions.js | 30 | ||||
| -rw-r--r-- | app/redux/connection/reducers.js | 35 | ||||
| -rw-r--r-- | app/redux/settings/actions.js | 4 | ||||
| -rw-r--r-- | app/redux/settings/reducers.js | 69 | ||||
| -rw-r--r-- | app/redux/store.js | 18 |
7 files changed, 163 insertions, 115 deletions
diff --git a/app/redux/account/actions.js b/app/redux/account/actions.js index 8932e6ae37..ca2bbdc7b6 100644 --- a/app/redux/account/actions.js +++ b/app/redux/account/actions.js @@ -36,13 +36,14 @@ type UpdateAccountHistoryAction = { accountHistory: Array<AccountToken>, }; -export type AccountAction = StartLoginAction - | LoginSuccessfulAction - | LoginFailedAction - | LoggedOutAction - | ResetLoginErrorAction - | UpdateAccountTokenAction - | UpdateAccountHistoryAction; +export type AccountAction = + | StartLoginAction + | LoginSuccessfulAction + | LoginFailedAction + | LoggedOutAction + | ResetLoginErrorAction + | UpdateAccountTokenAction + | UpdateAccountHistoryAction; function startLogin(accountToken?: AccountToken): StartLoginAction { return { diff --git a/app/redux/account/reducers.js b/app/redux/account/reducers.js index 7585d7adc0..fe10dce742 100644 --- a/app/redux/account/reducers.js +++ b/app/redux/account/reducers.js @@ -10,7 +10,7 @@ export type AccountReduxState = { accountHistory: Array<AccountToken>, expiry: ?string, // ISO8601 status: LoginState, - error: ?BackendError + error: ?BackendError, }; const initialState: AccountReduxState = { @@ -18,50 +18,73 @@ const initialState: AccountReduxState = { accountHistory: [], expiry: null, status: 'none', - error: null + error: null, }; -export default function(state: AccountReduxState = initialState, action: ReduxAction): AccountReduxState { - +export default function( + state: AccountReduxState = initialState, + action: ReduxAction, +): AccountReduxState { switch (action.type) { - case 'START_LOGIN': - return { ...state, ...{ - status: 'logging in', - accountToken: action.accountToken, - error: null, - }}; - case 'LOGIN_SUCCESSFUL': - return { ...state, ...{ - status: 'ok', - error: null, - expiry: action.expiry, - }}; - case 'LOGIN_FAILED': - return { ...state, ...{ - status: 'failed', - accountToken: null, - error: action.error, - }}; - case 'LOGGED_OUT': - return { ...state, ...{ - status: 'none', - accountToken: null, - expiry: null, - error: null, - }}; - case 'RESET_LOGIN_ERROR': - return { ...state, ...{ - status: 'none', - error: null, - }}; - case 'UPDATE_ACCOUNT_TOKEN': - return { ...state, ...{ - accountToken: action.token, - }}; - case 'UPDATE_ACCOUNT_HISTORY': - return { ...state, ...{ - accountHistory: action.accountHistory, - }}; + case 'START_LOGIN': + return { + ...state, + ...{ + status: 'logging in', + accountToken: action.accountToken, + error: null, + }, + }; + case 'LOGIN_SUCCESSFUL': + return { + ...state, + ...{ + status: 'ok', + error: null, + expiry: action.expiry, + }, + }; + case 'LOGIN_FAILED': + return { + ...state, + ...{ + status: 'failed', + accountToken: null, + error: action.error, + }, + }; + case 'LOGGED_OUT': + return { + ...state, + ...{ + status: 'none', + accountToken: null, + expiry: null, + error: null, + }, + }; + case 'RESET_LOGIN_ERROR': + return { + ...state, + ...{ + status: 'none', + error: null, + }, + }; + case 'UPDATE_ACCOUNT_TOKEN': + return { + ...state, + ...{ + accountToken: action.token, + }, + }; + case 'UPDATE_ACCOUNT_HISTORY': + return { + ...state, + ...{ + accountHistory: action.accountHistory, + }, + }; } return state; diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js index 6f0da8cecf..b4f1df09be 100644 --- a/app/redux/connection/actions.js +++ b/app/redux/connection/actions.js @@ -11,13 +11,12 @@ const disconnect = (backend: Backend) => () => backend.disconnect(); const copyIPAddress = (): ReduxThunk => { return (_, getState) => { const ip = getState().connection.ip; - if(ip) { + if (ip) { Clipboard.setText(ip); } }; }; - type ConnectingAction = { type: 'CONNECTING', }; @@ -48,12 +47,13 @@ type OfflineAction = { type: 'OFFLINE', }; -export type ConnectionAction = NewLocationAction - | ConnectingAction - | ConnectedAction - | DisconnectedAction - | OnlineAction - | OfflineAction; +export type ConnectionAction = + | NewLocationAction + | ConnectingAction + | ConnectedAction + | DisconnectedAction + | OnlineAction + | OfflineAction; function connecting(): ConnectingAction { return { @@ -92,6 +92,14 @@ function offline(): OfflineAction { }; } - -export default { connect, disconnect, copyIPAddress, newLocation, connecting, connected, disconnected, online, offline }; - +export default { + connect, + disconnect, + copyIPAddress, + newLocation, + connecting, + connected, + disconnected, + online, + offline, +}; diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js index f21d8ca544..a50fbf0757 100644 --- a/app/redux/connection/reducers.js +++ b/app/redux/connection/reducers.js @@ -24,29 +24,30 @@ const initialState: ConnectionReduxState = { city: null, }; - -export default function(state: ConnectionReduxState = initialState, action: ReduxAction): ConnectionReduxState { - +export default function( + state: ConnectionReduxState = initialState, + action: ReduxAction, +): ConnectionReduxState { switch (action.type) { - case 'NEW_LOCATION': - return { ...state, ...action.newLocation }; + case 'NEW_LOCATION': + return { ...state, ...action.newLocation }; - case 'CONNECTING': - return { ...state, ...{ status: 'connecting' }}; + case 'CONNECTING': + return { ...state, ...{ status: 'connecting' } }; - case 'CONNECTED': - return { ...state, ...{ status: 'connected' }}; + case 'CONNECTED': + return { ...state, ...{ status: 'connected' } }; - case 'DISCONNECTED': - return { ...state, ...{ status: 'disconnected' }}; + case 'DISCONNECTED': + return { ...state, ...{ status: 'disconnected' } }; - case 'ONLINE': - return { ...state, ...{ isOnline: true }}; + case 'ONLINE': + return { ...state, ...{ isOnline: true } }; - case 'OFFLINE': - return { ...state, ...{ isOnline: false }}; + case 'OFFLINE': + return { ...state, ...{ isOnline: false } }; - default: - return state; + default: + return state; } } diff --git a/app/redux/settings/actions.js b/app/redux/settings/actions.js index 02debd5b77..0d3e252778 100644 --- a/app/redux/settings/actions.js +++ b/app/redux/settings/actions.js @@ -26,7 +26,9 @@ function updateRelay(relay: RelaySettingsRedux): UpdateRelayAction { }; } -function updateRelayLocations(relayLocations: Array<RelayLocationRedux>): UpdateRelayLocationsAction { +function updateRelayLocations( + relayLocations: Array<RelayLocationRedux>, +): UpdateRelayLocationsAction { return { type: 'UPDATE_RELAY_LOCATIONS', relayLocations: relayLocations, diff --git a/app/redux/settings/reducers.js b/app/redux/settings/reducers.js index 39005fd486..f559c1f725 100644 --- a/app/redux/settings/reducers.js +++ b/app/redux/settings/reducers.js @@ -3,19 +3,21 @@ import type { ReduxAction } from '../store'; import type { RelayProtocol, RelayLocation } from '../../lib/ipc-facade'; -export type RelaySettingsRedux = {| - normal: { - location: 'any' | RelayLocation, - port: 'any' | number, - protocol: 'any' | RelayProtocol, - } -|} | {| - custom_tunnel_endpoint: { - host: string, - port: number, - protocol: RelayProtocol, - } -|}; +export type RelaySettingsRedux = + | {| + normal: { + location: 'any' | RelayLocation, + port: 'any' | number, + protocol: 'any' | RelayProtocol, + }, + |} + | {| + custom_tunnel_endpoint: { + host: string, + port: number, + protocol: RelayProtocol, + }, + |}; export type RelayLocationCityRedux = { name: string, @@ -44,31 +46,36 @@ const initialState: SettingsReduxState = { location: 'any', port: 'any', protocol: 'any', - } + }, }, relayLocations: [], allowLan: false, }; -export default function(state: SettingsReduxState = initialState, action: ReduxAction): SettingsReduxState { - - switch(action.type) { - case 'UPDATE_RELAY': - return { ...state, - relaySettings: action.relay, - }; +export default function( + state: SettingsReduxState = initialState, + action: ReduxAction, +): SettingsReduxState { + switch (action.type) { + case 'UPDATE_RELAY': + return { + ...state, + relaySettings: action.relay, + }; - case 'UPDATE_RELAY_LOCATIONS': - return { ...state, - relayLocations: action.relayLocations, - }; + case 'UPDATE_RELAY_LOCATIONS': + return { + ...state, + relayLocations: action.relayLocations, + }; - case 'UPDATE_ALLOW_LAN': - return { ...state, - allowLan: action.allowLan, - }; + case 'UPDATE_ALLOW_LAN': + return { + ...state, + allowLan: action.allowLan, + }; - default: - return state; + default: + return state; } } diff --git a/app/redux/store.js b/app/redux/store.js index d03849c0c4..8d74b605f6 100644 --- a/app/redux/store.js +++ b/app/redux/store.js @@ -23,7 +23,7 @@ import type { SettingsAction } from './settings/actions.js'; export type ReduxState = { account: AccountReduxState, connection: ConnectionReduxState, - settings: SettingsReduxState + settings: SettingsReduxState, }; export type ReduxAction = AccountAction | SettingsAction | ConnectionAction; @@ -32,7 +32,10 @@ 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 { +export default function configureStore( + initialState: ?ReduxState, + routerHistory: History, +): ReduxStore { const router = routerMiddleware(routerHistory); const actionCreators: { [string]: Function } = { @@ -44,14 +47,17 @@ export default function configureStore(initialState: ?ReduxState, routerHistory: }; const reducers = { - account, connection, settings, router: routerReducer + account, + connection, + settings, + router: routerReducer, }; - const middlewares = [ thunk, router ]; + const middlewares = [thunk, router]; const composeEnhancers = (() => { const reduxCompose = window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__; - if(process.env.NODE_ENV === 'development' && reduxCompose) { + if (process.env.NODE_ENV === 'development' && reduxCompose) { return reduxCompose({ actionCreators }); } return compose; @@ -59,7 +65,7 @@ export default function configureStore(initialState: ?ReduxState, routerHistory: const enhancer = composeEnhancers(applyMiddleware(...middlewares)); const rootReducer = combineReducers(reducers); - if(initialState) { + if (initialState) { return createStore(rootReducer, initialState, enhancer); } return createStore(rootReducer, enhancer); |
