diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/redux/account/actions.js | 15 | ||||
| -rw-r--r-- | app/redux/account/reducers.js | 13 | ||||
| -rw-r--r-- | app/redux/connection/actions.js | 21 | ||||
| -rw-r--r-- | app/redux/connection/reducers.js | 14 | ||||
| -rw-r--r-- | app/redux/settings/actions.js | 14 | ||||
| -rw-r--r-- | app/redux/settings/reducers.js | 13 | ||||
| -rw-r--r-- | app/redux/store.js | 14 |
7 files changed, 70 insertions, 34 deletions
diff --git a/app/redux/account/actions.js b/app/redux/account/actions.js index ab9b8cf463..0b828c678a 100644 --- a/app/redux/account/actions.js +++ b/app/redux/account/actions.js @@ -1,13 +1,20 @@ // @flow -import { createAction } from 'redux-actions'; import type { Backend } from '../../lib/backend'; import type { AccountReduxState } from './reducers.js'; -import type { ReduxAction } from '../store'; -export type LoginChangeAction = <T: $Shape<AccountReduxState>>(state: T) => ReduxAction<T>; +export type LoginChangeAction = { + type:'LOGIN_CHANGE', + newData: $Shape<AccountReduxState>, +}; + +function loginChange(data: $Shape<AccountReduxState>): LoginChangeAction { + return { + type: 'LOGIN_CHANGE', + newData: data, + }; +} -const loginChange: LoginChangeAction = createAction('USER_LOGIN_CHANGE'); const login = (backend: Backend, account: string) => () => backend.login(account); const logout = (backend: Backend) => () => backend.logout(); diff --git a/app/redux/account/reducers.js b/app/redux/account/reducers.js index b93a5b6948..d1fd284ee5 100644 --- a/app/redux/account/reducers.js +++ b/app/redux/account/reducers.js @@ -1,6 +1,4 @@ // @flow -import { handleActions } from 'redux-actions'; -import actions from './actions.js'; import type { ReduxAction } from '../store'; import type { BackendError } from '../../lib/backend'; @@ -20,8 +18,11 @@ const initialState: AccountReduxState = { error: null }; -export default handleActions({ - [actions.loginChange.toString()]: (state: AccountReduxState, action: ReduxAction<$Shape<AccountReduxState>>) => { - return { ...state, ...action.payload }; +export default function(state: AccountReduxState = initialState, action: ReduxAction): AccountReduxState { + + if (action.type === 'LOGIN_CHANGE') { + return { ...state, ...action.newData }; } -}, initialState); + + return state; +} diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js index 4639feaf65..aae63b5506 100644 --- a/app/redux/connection/actions.js +++ b/app/redux/connection/actions.js @@ -1,19 +1,16 @@ // @flow import { clipboard } from 'electron'; -import { createAction } from 'redux-actions'; import type { Backend } from '../../lib/backend'; import type { ConnectionReduxState } from './reducers.js'; -import type { ReduxAction, ReduxGetStateFn, ReduxDispatchFn } from '../store'; +import type { ReduxGetStateFn, ReduxDispatchFn } from '../store'; -export type ConnectionChangeAction = <T: $Shape<ConnectionReduxState>>(state: T) => ReduxAction<T>; -const connectionChange: ConnectionChangeAction = createAction('CONNECTION_CHANGE'); const connect = (backend: Backend, addr: string) => () => backend.connect(addr); const disconnect = (backend: Backend) => () => backend.disconnect(); const copyIPAddress = () => { - return (_dispatch: ReduxDispatchFn<*>, getState: ReduxGetStateFn) => { + return (_dispatch: ReduxDispatchFn, getState: ReduxGetStateFn) => { const ip: ?string = getState().connection.clientIp; if(ip) { clipboard.writeText(ip); @@ -21,4 +18,18 @@ const copyIPAddress = () => { }; }; + +export type ConnectionChangeAction = { + type: 'CONNECTION_CHANGE', + newData: $Shape<ConnectionReduxState>, +}; + +function connectionChange(newData: $Shape<ConnectionReduxState>): ConnectionChangeAction { + return { + type: 'CONNECTION_CHANGE', + newData: newData, + }; +} + + export default { connect, disconnect, copyIPAddress, connectionChange }; diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js index daf746c034..07bdf20b16 100644 --- a/app/redux/connection/reducers.js +++ b/app/redux/connection/reducers.js @@ -1,6 +1,4 @@ // @flow -import { handleActions } from 'redux-actions'; -import actions from './actions'; import type { ReduxAction } from '../store'; import type { Coordinate2d } from '../../types'; @@ -26,8 +24,12 @@ const initialState: ConnectionReduxState = { city: null, }; -export default handleActions({ - [actions.connectionChange.toString()]: (state: ConnectionReduxState, action: ReduxAction<$Shape<ConnectionReduxState>>) => { - return { ...state, ...action.payload }; + +export default function(state: ConnectionReduxState = initialState, action: ReduxAction): ConnectionReduxState { + + if (action.type === 'CONNECTION_CHANGE') { + return { ...state, ...action.newData }; } -}, initialState); + + return state; +} diff --git a/app/redux/settings/actions.js b/app/redux/settings/actions.js index 16a7a79414..7b806096b8 100644 --- a/app/redux/settings/actions.js +++ b/app/redux/settings/actions.js @@ -1,11 +1,17 @@ // @flow -import { createAction } from 'redux-actions'; import type { SettingsReduxState } from './reducers'; -import type { ReduxAction } from '../store'; -export type UpdateSettingsAction = <T: $Shape<SettingsReduxState>>(state: T) => ReduxAction<T>; +export type UpdateSettingsAction = { + type: 'UPDATE_SETTINGS', + newSettings: $Shape<SettingsReduxState>, +}; -const updateSettings: UpdateSettingsAction = createAction('SETTINGS_UPDATE'); +function updateSettings(newSettings: $Shape<SettingsReduxState>): UpdateSettingsAction { + return { + type: 'UPDATE_SETTINGS', + newSettings: newSettings, + }; +} export default { updateSettings }; diff --git a/app/redux/settings/reducers.js b/app/redux/settings/reducers.js index bd899d21f9..5594663dce 100644 --- a/app/redux/settings/reducers.js +++ b/app/redux/settings/reducers.js @@ -1,6 +1,4 @@ // @flow -import { handleActions } from 'redux-actions'; -import actions from './actions'; import { defaultServer } from '../../config'; @@ -16,8 +14,11 @@ const initialState: SettingsReduxState = { preferredServer: defaultServer }; -export default handleActions({ - [actions.updateSettings.toString()]: (state: SettingsReduxState, action: ReduxAction<$Shape<SettingsReduxState>>) => { - return { ...state, ...action.payload }; +export default function(state: SettingsReduxState = initialState, action: ReduxAction): SettingsReduxState { + + if (action.type === 'UPDATE_SETTINGS') { + return { ...state, ...action.newSettings }; } -}, initialState); + + return state; +} diff --git a/app/redux/store.js b/app/redux/store.js index 80060c59a9..76447efc17 100644 --- a/app/redux/store.js +++ b/app/redux/store.js @@ -16,15 +16,23 @@ import type { AccountReduxState } from './account/reducers.js'; import type { ConnectionReduxState } from './connection/reducers.js'; import type { SettingsReduxState } from './settings/reducers.js'; +import type { ConnectionChangeAction } from './connection/actions.js'; +import type { LoginChangeAction } from './account/actions.js'; +import type { UpdateSettingsAction } from './settings/actions.js'; + export type ReduxState = { account: AccountReduxState, connection: ConnectionReduxState, settings: SettingsReduxState }; -export type ReduxAction<T> = { type: string, payload: T } | Function; -export type ReduxStore = Store<ReduxState, ReduxAction<Object>>; +export type ReduxAction = Function + | LoginChangeAction + | UpdateSettingsAction + | ConnectionChangeAction; + +export type ReduxStore = Store<ReduxState, ReduxAction>; export type ReduxGetStateFn = () => ReduxState; -export type ReduxDispatchFn<T: *> = Dispatch<ReduxAction<T>>; +export type ReduxDispatchFn = Dispatch<ReduxAction>; export default function configureStore(initialState: ?ReduxState, routerHistory: History): ReduxStore { const router = routerMiddleware(routerHistory); |
