Move constants to it own dir (#12)

* Move constants to directory

* Use index to export constants
This commit is contained in:
Mike Piccolo 2016-10-15 09:09:24 -07:00 committed by it33
parent f6e551c45b
commit c8c4a0b010
7 changed files with 58 additions and 36 deletions

View file

@ -3,19 +3,16 @@
import {requestData, requestSuccess, requestFailure} from './helpers.js';
import {AsyncStorage} from 'react-native';
export const DEVICE_REQUEST = 'DEVICE_REQUEST';
export const DEVICE_SUCCESS = 'DEVICE_SUCCESS';
export const DEVICE_FAILURE = 'DEVICE_FAILURE';
import {DeviceTypes as types} from 'constants';
function fetchDevice() {
return async (dispatch) => {
try {
dispatch(requestData(DEVICE_REQUEST));
dispatch(requestData(types.DEVICE_REQUEST));
const json = await AsyncStorage.getItem('basic_info');
dispatch(requestSuccess(DEVICE_SUCCESS, JSON.parse(json)));
dispatch(requestSuccess(types.DEVICE_SUCCESS, JSON.parse(json)));
} catch (err) {
dispatch(requestFailure(DEVICE_FAILURE, {msg: 'failed to load local storage'}));
dispatch(requestFailure(types.DEVICE_FAILURE, {msg: 'failed to load local storage'}));
}
};
}

View file

@ -3,44 +3,33 @@
import Client from 'client/client_instance.js';
import {bindClientFunc} from './helpers.js';
export const PING_REQUEST = 'PING_REQUEST';
export const PING_SUCCESS = 'PING_SUCCESS';
export const PING_FAILURE = 'PING_FAILURE';
import {GeneralTypes as types} from 'constants';
export function getPing() {
return bindClientFunc(
Client.getPing,
PING_REQUEST,
PING_SUCCESS,
PING_FAILURE
types.PING_REQUEST,
types.PING_SUCCESS,
types.PING_FAILURE
);
}
export const CLIENT_CONFIG_REQUEST = 'CLIENT_CONFIG_REQUEST';
export const CLIENT_CONFIG_SUCCESS = 'CLIENT_CONFIG_SUCCESS';
export const CLIENT_CONFIG_FAILURE = 'CLIENT_CONFIG_FAILURE';
export function getClientConfig() {
return bindClientFunc(
Client.getClientConfig,
CLIENT_CONFIG_REQUEST,
CLIENT_CONFIG_SUCCESS,
CLIENT_CONFIG_FAILURE
types.CLIENT_CONFIG_REQUEST,
types.CLIENT_CONFIG_SUCCESS,
types.CLIENT_CONFIG_FAILURE
);
}
export const LOG_CLIENT_ERROR_REQUEST = 'LOG_CLIENT_ERROR_REQUEST';
export const LOG_CLIENT_ERROR_SUCCESS = 'LOG_CLIENT_ERROR_SUCCESS';
export const LOG_CLIENT_ERROR_FAILURE = 'LOG_CLIENT_ERROR_FAILURE';
export function logClientError(message, level = 'ERROR') {
return bindClientFunc(
Client.logClientError,
LOG_CLIENT_ERROR_REQUEST,
LOG_CLIENT_ERROR_SUCCESS,
LOG_CLIENT_ERROR_FAILURE,
types.LOG_CLIENT_ERROR_REQUEST,
types.LOG_CLIENT_ERROR_SUCCESS,
types.LOG_CLIENT_ERROR_FAILURE,
message,
level
);
}
}

3
src/constants/device.js Normal file
View file

@ -0,0 +1,3 @@
export const DEVICE_REQUEST = 'DEVICE_REQUEST';
export const DEVICE_SUCCESS = 'DEVICE_SUCCESS';
export const DEVICE_FAILURE = 'DEVICE_FAILURE';

11
src/constants/general.js Normal file
View file

@ -0,0 +1,11 @@
export const PING_REQUEST = 'PING_REQUEST';
export const PING_SUCCESS = 'PING_SUCCESS';
export const PING_FAILURE = 'PING_FAILURE';
export const CLIENT_CONFIG_REQUEST = 'CLIENT_CONFIG_REQUEST';
export const CLIENT_CONFIG_SUCCESS = 'CLIENT_CONFIG_SUCCESS';
export const CLIENT_CONFIG_FAILURE = 'CLIENT_CONFIG_FAILURE';
export const LOG_CLIENT_ERROR_REQUEST = 'LOG_CLIENT_ERROR_REQUEST';
export const LOG_CLIENT_ERROR_SUCCESS = 'LOG_CLIENT_ERROR_SUCCESS';
export const LOG_CLIENT_ERROR_FAILURE = 'LOG_CLIENT_ERROR_FAILURE';

7
src/constants/index.js Normal file
View file

@ -0,0 +1,7 @@
import * as DeviceTypes from './device';
import * as GeneralTypes from './general';
export {
DeviceTypes,
GeneralTypes
};

View file

@ -2,8 +2,13 @@
// See License.txt for license information.
import {handle, initialState} from './helpers.js';
import * as Types from 'actions/device.js';
import {DeviceTypes as types} from 'constants';
export default function device(state = initialState(), action) {
return handle(Types.DEVICE_REQUEST, Types.DEVICE_SUCCESS, Types.DEVICE_FAILURE, state, action);
}
return handle(
types.DEVICE_REQUEST,
types.DEVICE_SUCCESS,
types.DEVICE_FAILURE,
state,
action);
}

View file

@ -3,17 +3,27 @@
import {combineReducers} from 'redux';
import {initialState, handle} from './helpers.js';
import * as Types from 'actions/general.js';
import {GeneralTypes as types} from 'constants';
export function clientConfig(state = initialState(), action) {
return handle(Types.CLIENT_CONFIG_REQUEST, Types.CLIENT_CONFIG_SUCCESS, Types.CLIENT_CONFIG_FAILURE, state, action);
return handle(
types.CLIENT_CONFIG_REQUEST,
types.CLIENT_CONFIG_SUCCESS,
types.CLIENT_CONFIG_FAILURE,
state,
action);
}
export function ping(state = initialState(), action) {
return handle(Types.PING_REQUEST, Types.PING_SUCCESS, Types.PING_FAILURE, state, action);
return handle(
types.PING_REQUEST,
types.PING_SUCCESS,
types.PING_FAILURE,
state,
action);
}
export default combineReducers({
clientConfig,
ping
});
});