Overview
Idea suggests that we contain language within a module, auto-generate plurals and any other pieces off of a singular base, and consume the pieces throughout our code.
constants/language.js
export const USER = {
SINGULAR: 'account_holder',
PLURAL: () => `${USER.SINGULAR}s`
};
export const BILLING = {
SINGULAR: 'bill',
PLURAL: () => `${BILLING.SINGULAR}s`
};
reducers/user.js
import { Map } from 'immutable';
import { USER } from '../constants/language';
import {
SESSION_AUTHENTICATE_REQUEST,
SESSION_AUTHENTICATE_FAILURE,
SESSION_AUTHENTICATE_SUCCESS
} from '../actions';
const USER_SINGULAR_KEY = USER.SINGULAR;
import { Map } from 'immutable';
import { USER } from '../constants/language';
import {
SESSION_AUTHENTICATE_REQUEST,
SESSION_AUTHENTICATE_FAILURE,
SESSION_AUTHENTICATE_SUCCESS
} from '../actions';
const USER_SINGULAR_KEY = USER.SINGULAR;
const initial_state = Map({
is_logged_in: false,
is_logging_in: false,
[USER_SINGULAR_KEY]: Map()
});
function session_reducer(state = initialState, action) {
switch (action.type) {
case SESSION_AUTHENTICATE_REQUEST:
return state.merge({
is_logging_in: true
});
case SESSION_AUTHENTICATE_FAILURE:
return state.merge({
is_logging_in: false
});
case SESSION_AUTHENTICATE_SUCCESS:
return state.merge({
is_logged_in: true,
is_logging_in: false,
[USER_SINGULAR_KEY]: Map(action.payload)
});
default:
return state;
}
}
translated reducers/user.js
...
function sessionReducer() {
switch (action.type) {
case <SESSION_AUTHENTICATION_CONSTANT>:
return state.merge({
account_holder: action.payload
});
}
}