This commit is contained in:
crusader 2017-06-28 16:50:19 +09:00
parent 9139cd82ae
commit ffbc0f7ecc
10 changed files with 100 additions and 46 deletions

View File

View File

@ -1,5 +1,7 @@
import { Action, combineReducers } from 'redux'; import { Action, combineReducers } from 'redux';
import { routerReducer, RouterState } from 'react-router-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'; import * as Member from 'member';
@ -12,3 +14,26 @@ export const reducer = combineReducers<State>({
member: Member.reducer, member: Member.reducer,
router: routerReducer, 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);
// }

View File

@ -1,6 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import * as ReactDOM from 'react-dom'; import * as ReactDOM from 'react-dom';
import createSagaMiddleware, { SagaMiddleware } from 'redux-saga'; import createSagaMiddleware, { SagaMiddleware } from 'redux-saga';
import { fork } from 'redux-saga/effects';
import { createHashHistory } from 'history'; import { createHashHistory } from 'history';
@ -12,8 +13,10 @@ import * as injectTapEventPlugin from 'react-tap-event-plugin';
import * as system from 'commons/util/system'; import * as system from 'commons/util/system';
import configureStore from 'config/configureStore'; import configureStore from 'config/configureStore';
import { sagas } from 'config/configureRedux';
import muiTheme from 'config/configureMuiTheme'; import muiTheme from 'config/configureMuiTheme';
import App from 'app/views/container/component/App'; import App from 'app/views/container/component/App';
injectTapEventPlugin(); injectTapEventPlugin();
@ -40,6 +43,7 @@ function* app(): any {
appContainer, appContainer,
); );
sagaMiddleware.run(sagas);
ReactDOM.render( ReactDOM.render(
<Provider store={store}> <Provider store={store}>

View File

@ -1,4 +1,7 @@
import { Action, combineReducers } from 'redux'; import { Action, combineReducers } from 'redux';
import { SagaIterator } from 'redux-saga';
import { fork, ForkEffect } from 'redux-saga/effects';
import IModule from 'commons/redux/Module'; import IModule from 'commons/redux/Module';
import * as signin from './signin'; import * as signin from './signin';
@ -16,3 +19,7 @@ export const reducer = combineReducers<State>({
signout: signout.reducer, signout: signout.reducer,
signup: signup.reducer, signup: signup.reducer,
}); });
export function* sagas(): SagaIterator {
yield fork(signin.sagas);
}

View File

@ -25,14 +25,14 @@ export const actions: Actions = {
requestSuccess(member: Member): Action<Member> { requestSuccess(member: Member): Action<Member> {
return { return {
type: actionTypes.REQUEST, type: actionTypes.REQUEST_SUCCESS,
payload: member, payload: member,
}; };
}, },
requestFailure(error: Error): Action { requestFailure(error: Error): Action {
return { return {
type: actionTypes.REQUEST, type: actionTypes.REQUEST_FAILURE,
error: error, error: error,
}; };
}, },

View File

@ -1,2 +1,3 @@
export * from './state'; export * from './state';
export * from './reducer'; export * from './reducer';
export * from './saga';

View File

@ -1,43 +1,8 @@
import { takeLatest, SagaIterator } from 'redux-saga'; import { SagaIterator } from 'redux-saga';
import { call, put } from 'redux-saga/effects'; import { fork, ForkEffect } from 'redux-saga/effects';
import Action from 'commons/redux/Action'; import { watchSignin } from './signin';
import Member from 'member/api/model/Member'; export function* sagas(): SagaIterator {
import actions from '../action'; yield fork(watchSignin);
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);
} }

View 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);
}

View File

@ -18,13 +18,13 @@ export const actions: Actions = {
requestSuccess(): Action { requestSuccess(): Action {
return { return {
type: actionTypes.REQUEST, type: actionTypes.REQUEST_SUCCESS,
}; };
}, },
requestFailure(error: Error): Action { requestFailure(error: Error): Action {
return { return {
type: actionTypes.REQUEST, type: actionTypes.REQUEST_FAILURE,
error: error, error: error,
}; };
}, },

View File

@ -21,14 +21,14 @@ export const actions: Actions = {
requestSuccess(member: Member): Action<Member> { requestSuccess(member: Member): Action<Member> {
return { return {
type: actionTypes.REQUEST, type: actionTypes.REQUEST_SUCCESS,
payload: member, payload: member,
}; };
}, },
requestFailure(error: Error): Action { requestFailure(error: Error): Action {
return { return {
type: actionTypes.REQUEST, type: actionTypes.REQUEST_FAILURE,
error: error, error: error,
}; };
}, },