mdp-cli
v1.3.3
Published
Mdp Web Starter Template
Downloads
6
Maintainers
Readme
MDP-CLI
MDP Group Web Department React & NodeJS Starter Kit.
Installation
Use npm the package manager to install. The package must be installed globally ( -g ).
$ npm i -g mdp-cli
React Usage
$ mdp-create-react
NodeJS Usage
$ mdp-create-nodejs
React Redux & Saga Generator
$ mdp-create-redux 'CONSTANT_NAME' 'ACTION_PARAMTERS,ACTION_PARAMTERS1,ACTION_PARAMTERS2' 'REDUCERS_STATE_NAME'
Usage :
mdp-create-redux user name,email userData
Output;
## store/constants.js
// USER CONSTANTS
export const GET_USER = 'GET_USER';
export const SET_USER = 'SET_USER';
## store/actions.js
// GET_USER
export const getUser = (name, email) => ({
type: constants.GET_USER, name, email,
});
// SET_USER
export const setUser = (data) => ({
type: constants.SET_USER, data,
});
## store/reducers.js
switch (actions.type) {
case constants.SET_TOAST: {
const oldToast = state.toast;
const toast = { open: action.value, message: action.message, variant: action.variant };
if (!action.value) {
toast.message = '';
toast.variant = oldToast.variant;
}
return { ...state, toast };
}
// New Added Line Start
case constants.SET_USER: {
return { ...state, userData: action.data };
}
// New Added Line End
default: {
return state;
}
}
## store/sagas.js
function* getUser(name, email) {
const jsonStr = JSON.stringify({ name, email });
const result = yield call(request, url.USER, 'POST', jsonStr, true);
if (result !== 'invalid') {
if (result.status) {
yield put(actions.setUser(data(result.data)));
} else {
yield put(actions.setToast(true, result.message, 'error'));
}
} else {
yield put(actions.setToast(true, 'Could not establish a connection with the server!', 'warning'));
}
}
...
function* getUserWatcher() {
while (true) {
const action = yield take(constants.GET_USER);
yield call(getUser, action.name, action.email);
}
}
...
export default function* rootSaga() {
yield all([
getUserWatcher(), // Added rootSaga
getInitWatcher(),
]);
}
## store/selectors.js
export const selectUser = () => createSelector(
domain,
(substate) => substate.userData,
);
Need Support?
if you need support you can mail [email protected]