diff options
| -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 | ||||
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | test/reducers.spec.js | 28 | ||||
| -rw-r--r-- | yarn.lock | 15 |
10 files changed, 86 insertions, 62 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); diff --git a/package.json b/package.json index 81f44ca69d..00e7ac00bc 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "react-router-redux": "5.0.0-alpha.6", "react-transition-group": "^1.2.0", "redux": "^3.0.0", - "redux-actions": "^2.0.1", "redux-thunk": "^2.2.0", "uuid": "^3.0.1", "validated": "^1.1.0" diff --git a/test/reducers.spec.js b/test/reducers.spec.js index 5a0ec8f0a7..23a8e91f89 100644 --- a/test/reducers.spec.js +++ b/test/reducers.spec.js @@ -5,45 +5,47 @@ import accountReducer from '../app/redux/account/reducers'; import connectionReducer from '../app/redux/connection/reducers'; import settingsReducer from '../app/redux/settings/reducers'; import { defaultServer } from '../app/config'; +import { BackendError } from '../app/lib/backend'; describe('reducers', () => { + const previousState: any = {}; it('should handle USER_LOGIN_CHANGE', () => { const action = { - type: 'USER_LOGIN_CHANGE', - payload: { - account: '1111', + type: 'LOGIN_CHANGE', + newData: { + accountNumber: '1111', status: 'failed', - error: new Error('Something went wrong') + error: new BackendError('INVALID_ACCOUNT') } }; - const test = Object.assign({}, action.payload); - expect(accountReducer({}, action)).to.deep.equal(test); + const test = Object.assign({}, action.newData); + expect(accountReducer(previousState, action)).to.deep.equal(test); }); it('should handle CONNECTION_CHANGE', () => { const action = { type: 'CONNECTION_CHANGE', - payload: { + newData: { status: 'connected', serverAddress: '2.1.1.2', clientIp: '2.1.1.1' } }; - const test = Object.assign({}, action.payload); - expect(connectionReducer({}, action)).to.deep.equal(test); + const test = Object.assign({}, action.newData); + expect(connectionReducer(previousState, action)).to.deep.equal(test); }); it('should handle SETTINGS_UPDATE', () => { const action = { - type: 'SETTINGS_UPDATE', - payload: { + type: 'UPDATE_SETTINGS', + newSettings: { autoSecure: true, preferredServer: defaultServer } }; - const test = Object.assign({}, action.payload); - expect(settingsReducer({}, action)).to.deep.equal(test); + const test = Object.assign({}, action.newSettings); + expect(settingsReducer(previousState, action)).to.deep.equal(test); }); }); @@ -3384,7 +3384,7 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" -lodash-es@^4.17.4, lodash-es@^4.2.0, lodash-es@^4.2.1: +lodash-es@^4.2.0, lodash-es@^4.2.1: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.4.tgz#dcc1d7552e150a0640073ba9cb31d70f032950e7" @@ -4464,19 +4464,6 @@ redent@^1.0.0: indent-string "^2.1.0" strip-indent "^1.0.1" -reduce-reducers@^0.1.0: - version "0.1.2" - resolved "https://registry.yarnpkg.com/reduce-reducers/-/reduce-reducers-0.1.2.tgz#fa1b4718bc5292a71ddd1e5d839c9bea9770f14b" - -redux-actions@^2.0.1: - version "2.0.3" - resolved "https://registry.yarnpkg.com/redux-actions/-/redux-actions-2.0.3.tgz#1550aba9def179166ccd234d07672104a736d889" - dependencies: - invariant "^2.2.1" - lodash "^4.13.1" - lodash-es "^4.17.4" - reduce-reducers "^0.1.0" - redux-mock-store@^1.2.2: version "1.2.3" resolved "https://registry.yarnpkg.com/redux-mock-store/-/redux-mock-store-1.2.3.tgz#1b3ad299da91cb41ba30d68e3b6f024475fb9e1b" |
