member redux push

This commit is contained in:
geek 2017-07-04 16:14:21 +09:00
parent 3e79487f8f
commit 6c31de500d
7 changed files with 174 additions and 18 deletions

View File

@ -36,6 +36,9 @@ export class MemberService extends Service {
return null;
}
public modify(member: Member): Member {
return null;
}
}
export default MemberService;

View File

@ -1,3 +1,41 @@
/**
* Created by geek on 17. 7. 3.
*/
import Action from '@overflow/commons/redux/Action';
import Member from '@overflow/member/api/model/Member';
import ModifyPayload from '../payload/ModifyPayload';
// Action Type
export type REQUEST = '@overflow/member/modify/REQUEST';
export type REQUEST_SUCCESS = '@overflow/member/modify/REQUEST_SUCCESS';
export type REQUEST_FAILURE = '@overflow/member/modify/REQUEST_FAILURE';
export const REQUEST: REQUEST = '@overflow/member/modify/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/member/modify/REQUEST_SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/member/modify/REQUEST_FAILURE';
// Action Creater
export type request = (member: Member) => Action<ModifyPayload>;
export type requestSuccess = (member: Member) => Action<Member>;
export type requestFailure = (error: Error) => Action;
export const request: request = (member: Member): Action<ModifyPayload> => {
return {
type: REQUEST,
payload: {
member: member,
},
};
};
export const requestSuccess: requestSuccess = (member: Member): Action<Member> => {
return {
type: REQUEST_SUCCESS,
payload: member,
};
};
export const requestFailure: requestFailure = (error: Error): Action => {
return {
type: REQUEST_FAILURE,
error: error,
};
};

View File

@ -1,3 +1,41 @@
/**
* Created by geek on 17. 7. 3.
*/
import Action from '@overflow/commons/redux/Action';
import Member from '@overflow/member/api/model/Member';
import ReadPayload from '../payload/ReadPayload';
// Action Type
export type REQUEST = '@overflow/member/read/REQUEST';
export type REQUEST_SUCCESS = '@overflow/member/read/REQUEST_SUCCESS';
export type REQUEST_FAILURE = '@overflow/member/read/REQUEST_FAILURE';
export const REQUEST: REQUEST = '@overflow/member/read/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/member/read/REQUEST_SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/member/read/REQUEST_FAILURE';
// Action Creater
export type request = (id: number) => Action<ReadPayload>;
export type requestSuccess = (member: Member) => Action<Member>;
export type requestFailure = (error: Error) => Action;
export const request: request = (id: number): Action<ReadPayload> => {
return {
type: REQUEST,
payload: {
id: id,
},
};
};
export const requestSuccess: requestSuccess = (member: Member): Action<Member> => {
return {
type: REQUEST_SUCCESS,
payload: member,
};
};
export const requestFailure: requestFailure = (error: Error): Action => {
return {
type: REQUEST_FAILURE,
error: error,
};
};

View File

@ -1,3 +1,6 @@
/**
* Created by geek on 17. 7. 3.
*/
import Member from '../../api/model/Member';
interface ModifyPayload {
member: Member;
}
export default ModifyPayload;

View File

@ -1,3 +1,5 @@
/**
* Created by geek on 17. 7. 3.
*/
interface ReadPayload {
id: number;
}
export default ReadPayload;

View File

@ -1,3 +1,39 @@
/**
* Created by geek on 17. 7. 3.
*/
import { SagaIterator } from 'redux-saga';
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
import AppContext from '@overflow/commons/context';
import Action from '@overflow/commons/redux/Action';
import Member from '../../api/model/Member';
import MemberService from '../../api/service/MemberService';
import * as ModifyActions from '../action/modify';
import ModifyPayload from '../payload/ModifyPayload';
function* modify(action: Action<ModifyPayload>): SagaIterator {
try {
const tempMember = action.payload.member;
// yield put({
// type: types.SENDING_REQUEST,
// payload: {sendingRequest: true},
// });
const member = yield call(AppContext.getService<MemberService>().modify, tempMember);
// if (responseBody.token === undefined) {
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
// }
yield put(ModifyActions.requestSuccess(member));
} catch (e) {
yield put(ModifyActions.requestFailure(e));
} finally {
// yield put({
// type: types.SENDING_REQUEST,
// payload: {sendingRequest: false},
// });
}
}
export function* watchMemberModify(): SagaIterator {
yield takeLatest(ModifyActions.REQUEST, modify);
}

View File

@ -1,3 +1,39 @@
/**
* Created by geek on 17. 7. 3.
*/
import { SagaIterator } from 'redux-saga';
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
import AppContext from '@overflow/commons/context';
import Action from '@overflow/commons/redux/Action';
import Member from '../../api/model/Member';
import MemberService from '../../api/service/MemberService';
import * as ReadActions from '../action/read';
import ReadPayload from '../payload/ReadPayload';
function* read(action: Action<ReadPayload>): SagaIterator {
try {
const id = action.payload.id;
// yield put({
// type: types.SENDING_REQUEST,
// payload: {sendingRequest: true},
// });
const member = yield call(AppContext.getService<MemberService>().read, id);
// if (responseBody.token === undefined) {
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
// }
yield put(ReadActions.requestSuccess(member));
} catch (e) {
yield put(ReadActions.requestFailure(e));
} finally {
// yield put({
// type: types.SENDING_REQUEST,
// payload: {sendingRequest: false},
// });
}
}
export function* watchMemberRead(): SagaIterator {
yield takeLatest(ReadActions.REQUEST, read);
}