Repository URL to install this package:
|
Version:
4.2.0 ▾
|
import { ActionTypes } from '../actions';
const reducer = (state = {}, action) => {
switch (action.type) {
case ActionTypes.CHANGE_LOCALE:
return {
...state,
locale: action.payload.locale,
};
case ActionTypes.FETCH_MESSAGES:
return {
...state,
loading: true,
error: null,
};
case ActionTypes.FETCH_MESSAGES_SUCCESS: {
const messages = {
...state.messages,
[action.payload.locale]: action.payload.messages,
};
return {
...state,
loading: false,
error: null,
messages,
};
}
case ActionTypes.FETCH_MESSAGES_ERROR: {
return {
...state,
loading: false,
error: action.payload.error,
};
}
default:
return state;
}
};
/**
* Creates a reducer that can be used with [`combineReducer`](http://redux.js.org/docs/api/combineReducers.html)
*/
export default (options = {}) => ({
[options.domain || 'i18n']: reducer,
});