ing
This commit is contained in:
parent
9139cd82ae
commit
ffbc0f7ecc
0
src/ts/commons/redux/saga.ts
Normal file
0
src/ts/commons/redux/saga.ts
Normal file
|
@ -1,5 +1,7 @@
|
|||
import { Action, combineReducers } from 'redux';
|
||||
import { routerReducer, RouterState } from 'react-router-redux';
|
||||
import { SagaIterator } from 'redux-saga';
|
||||
import { Effect, fork, ForkEffect } from 'redux-saga/effects';
|
||||
|
||||
import * as Member from 'member';
|
||||
|
||||
|
@ -12,3 +14,26 @@ export const reducer = combineReducers<State>({
|
|||
member: Member.reducer,
|
||||
router: routerReducer,
|
||||
});
|
||||
|
||||
export function* sagas(): SagaIterator {
|
||||
yield fork(Member.sagas);
|
||||
}
|
||||
|
||||
|
||||
// export function* sagas(): Iterator<Effect> {
|
||||
// function* itor(values: {[key: string]: string | any}): Iterator<Effect> {
|
||||
// for (let name in values) {
|
||||
// if (values.hasOwnProperty(name)) {
|
||||
// let saga = values[name];
|
||||
// console.log('key:' + name + ' value:' + saga);
|
||||
// if (typeof saga === 'object') {
|
||||
// itor(saga);
|
||||
// } else {
|
||||
// yield fork(saga);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// itor(_sagas);
|
||||
// }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import createSagaMiddleware, { SagaMiddleware } from 'redux-saga';
|
||||
import { fork } from 'redux-saga/effects';
|
||||
import { createHashHistory } from 'history';
|
||||
|
||||
|
||||
|
@ -12,8 +13,10 @@ import * as injectTapEventPlugin from 'react-tap-event-plugin';
|
|||
import * as system from 'commons/util/system';
|
||||
|
||||
import configureStore from 'config/configureStore';
|
||||
import { sagas } from 'config/configureRedux';
|
||||
import muiTheme from 'config/configureMuiTheme';
|
||||
|
||||
|
||||
import App from 'app/views/container/component/App';
|
||||
|
||||
injectTapEventPlugin();
|
||||
|
@ -40,6 +43,7 @@ function* app(): any {
|
|||
appContainer,
|
||||
);
|
||||
|
||||
sagaMiddleware.run(sagas);
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { Action, combineReducers } from 'redux';
|
||||
import { SagaIterator } from 'redux-saga';
|
||||
import { fork, ForkEffect } from 'redux-saga/effects';
|
||||
|
||||
import IModule from 'commons/redux/Module';
|
||||
|
||||
import * as signin from './signin';
|
||||
|
@ -16,3 +19,7 @@ export const reducer = combineReducers<State>({
|
|||
signout: signout.reducer,
|
||||
signup: signup.reducer,
|
||||
});
|
||||
|
||||
export function* sagas(): SagaIterator {
|
||||
yield fork(signin.sagas);
|
||||
}
|
||||
|
|
|
@ -25,14 +25,14 @@ export const actions: Actions = {
|
|||
|
||||
requestSuccess(member: Member): Action<Member> {
|
||||
return {
|
||||
type: actionTypes.REQUEST,
|
||||
type: actionTypes.REQUEST_SUCCESS,
|
||||
payload: member,
|
||||
};
|
||||
},
|
||||
|
||||
requestFailure(error: Error): Action {
|
||||
return {
|
||||
type: actionTypes.REQUEST,
|
||||
type: actionTypes.REQUEST_FAILURE,
|
||||
error: error,
|
||||
};
|
||||
},
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
export * from './state';
|
||||
export * from './reducer';
|
||||
export * from './saga';
|
||||
|
|
|
@ -1,43 +1,8 @@
|
|||
import { takeLatest, SagaIterator } from 'redux-saga';
|
||||
import { call, put } from 'redux-saga/effects';
|
||||
import { SagaIterator } from 'redux-saga';
|
||||
import { fork, ForkEffect } from 'redux-saga/effects';
|
||||
|
||||
import Action from 'commons/redux/Action';
|
||||
import { watchSignin } from './signin';
|
||||
|
||||
import Member from 'member/api/model/Member';
|
||||
import actions from '../action';
|
||||
import actionTypes from '../action/type';
|
||||
import SigninPayload from '../payload/SigninPayload';
|
||||
|
||||
export function* signin(action: Action<SigninPayload>): SagaIterator {
|
||||
try {
|
||||
const {signinId, signinPw} = action.payload;
|
||||
// yield put({
|
||||
// type: types.SENDING_REQUEST,
|
||||
// payload: {sendingRequest: true},
|
||||
// });
|
||||
|
||||
// const responseBody = yield call(api.login, signinId, signinPw);
|
||||
|
||||
// if (responseBody.token === undefined) {
|
||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
||||
// }
|
||||
let member: Member = {
|
||||
email: 'crusader@loafle.com',
|
||||
name: 'crusader',
|
||||
phone: '02-900-9000',
|
||||
companyName: 'LOAFLE',
|
||||
};
|
||||
yield put(actions.requestSuccess(member));
|
||||
} catch (e) {
|
||||
yield put(actions.requestFailure(e));
|
||||
} finally {
|
||||
// yield put({
|
||||
// type: types.SENDING_REQUEST,
|
||||
// payload: {sendingRequest: false},
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
export function* watchSignin(): any {
|
||||
yield takeLatest(actionTypes.REQUEST, signin);
|
||||
export function* sagas(): SagaIterator {
|
||||
yield fork(watchSignin);
|
||||
}
|
||||
|
|
52
src/ts/member/signin/redux/saga/signin.ts
Normal file
52
src/ts/member/signin/redux/saga/signin.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { channel, takeEvery, takeLatest, SagaIterator } from 'redux-saga';
|
||||
import { call, Effect, fork, ForkEffect, put, TakeEffect } from 'redux-saga/effects';
|
||||
|
||||
import Action from 'commons/redux/Action';
|
||||
|
||||
import Member from 'member/api/model/Member';
|
||||
import actions from '../action';
|
||||
import actionTypes from '../action/type';
|
||||
import SigninPayload from '../payload/SigninPayload';
|
||||
|
||||
const apiSignin = (signinId: string, signinPw: string): Promise<Member> => {
|
||||
return new Promise<Member>(resolve => {
|
||||
setTimeout(() => {
|
||||
let member: Member = {
|
||||
email: 'crusader@loafle.com',
|
||||
name: 'crusader',
|
||||
phone: '02-900-9000',
|
||||
companyName: 'LOAFLE',
|
||||
};
|
||||
|
||||
resolve(member);
|
||||
}, 1000);
|
||||
});
|
||||
};
|
||||
|
||||
function* signin(action: Action<SigninPayload>): Iterable<Effect> {
|
||||
try {
|
||||
const {signinId, signinPw} = action.payload;
|
||||
// yield put({
|
||||
// type: types.SENDING_REQUEST,
|
||||
// payload: {sendingRequest: true},
|
||||
// });
|
||||
|
||||
const member = yield call(apiSignin, signinId, signinPw);
|
||||
|
||||
// if (responseBody.token === undefined) {
|
||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
||||
// }
|
||||
yield put(actions.requestSuccess(member));
|
||||
} catch (e) {
|
||||
yield put(actions.requestFailure(e));
|
||||
} finally {
|
||||
// yield put({
|
||||
// type: types.SENDING_REQUEST,
|
||||
// payload: {sendingRequest: false},
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
export function* watchSignin(): Iterable<SagaIterator> {
|
||||
yield takeLatest(actionTypes.REQUEST, signin);
|
||||
}
|
|
@ -18,13 +18,13 @@ export const actions: Actions = {
|
|||
|
||||
requestSuccess(): Action {
|
||||
return {
|
||||
type: actionTypes.REQUEST,
|
||||
type: actionTypes.REQUEST_SUCCESS,
|
||||
};
|
||||
},
|
||||
|
||||
requestFailure(error: Error): Action {
|
||||
return {
|
||||
type: actionTypes.REQUEST,
|
||||
type: actionTypes.REQUEST_FAILURE,
|
||||
error: error,
|
||||
};
|
||||
},
|
||||
|
|
|
@ -21,14 +21,14 @@ export const actions: Actions = {
|
|||
|
||||
requestSuccess(member: Member): Action<Member> {
|
||||
return {
|
||||
type: actionTypes.REQUEST,
|
||||
type: actionTypes.REQUEST_SUCCESS,
|
||||
payload: member,
|
||||
};
|
||||
},
|
||||
|
||||
requestFailure(error: Error): Action {
|
||||
return {
|
||||
type: actionTypes.REQUEST,
|
||||
type: actionTypes.REQUEST_FAILURE,
|
||||
error: error,
|
||||
};
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user