Async Request

This commit is contained in:
crusader 2017-08-16 14:55:57 +09:00
parent 1c32a26e8b
commit 99724e10ce
6 changed files with 59 additions and 14 deletions

View File

@ -0,0 +1,18 @@
import Action from '@overflow/commons/redux/Action';
import AsyncRequestSendingPayload from '../payload/AsyncRequestSendingPayload';
// Action Type
export type SENDING = '@overflow/app/async/SENDING';
export const SENDING: SENDING = '@overflow/app/async/SENDING';
// Action Creater
export type sending = (complete: boolean) => Action<AsyncRequestSendingPayload>;
export const sending: sending = (complete: boolean): Action<AsyncRequestSendingPayload> => {
return {
type: SENDING,
payload: {
complete: complete,
},
};
};

View File

@ -0,0 +1,5 @@
export interface AsyncRequestSendingPayload {
complete: boolean;
}
export default AsyncRequestSendingPayload;

View File

@ -0,0 +1,20 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import AsyncRequestSendingPayload from '../payload/AsyncRequestSendingPayload';
import * as AsyncRequestSendingActions from '../action/asyncRequestSending';
import AsyncRequestSendingState, {
defaultState as AsyncRequestSendingDefaultState,
} from '../state/AsyncRequestSending';
const reducer: ReducersMapObject = {
[AsyncRequestSendingActions.SENDING]: (state: AsyncRequestSendingState = AsyncRequestSendingDefaultState,
action: Action<AsyncRequestSendingPayload>): AsyncRequestSendingState => {
return {
complete: action.payload.complete,
};
},
};
export default reducer;

View File

@ -2,13 +2,13 @@ import { SagaIterator } from 'redux-saga';
import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects'; import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects';
import Action from '@overflow/commons/redux/Action'; import Action from '@overflow/commons/redux/Action';
import SagaWatcher from '@overflow/commons/redux/saga/SagaWatcher';
import * as AsyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; import * as AsyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
import AsyncRequestPayload from '@overflow/commons/redux/payload/AsyncRequestPayload';
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC'; import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
import AsyncRequestPayload from '@overflow/commons/redux/payload/AsyncRequestPayload'; import * as AppAsyncRequestSendingActions from '../action/asyncRequestSending';
import SagaWatcher from '@overflow/commons/redux/saga/SagaWatcher';
export class AsyncRequest implements SagaWatcher { export class AsyncRequest implements SagaWatcher {
private _webSocketRPC: WebSocketRPC; private _webSocketRPC: WebSocketRPC;
@ -20,10 +20,7 @@ export class AsyncRequest implements SagaWatcher {
private * request(webSocketRPC: WebSocketRPC, action: Action<AsyncRequestPayload>): SagaIterator { private * request(webSocketRPC: WebSocketRPC, action: Action<AsyncRequestPayload>): SagaIterator {
const {service, method, requestType, args} = action.payload; const {service, method, requestType, args} = action.payload;
try { try {
// yield put({ yield put(AppAsyncRequestSendingActions.sending(false));
// type: types.SENDING_REQUEST,
// payload: {sendingRequest: true},
// });`${service}.${method}`
let result = yield call({context: webSocketRPC, fn: webSocketRPC.Call}, `${service}.${method}`, args); let result = yield call({context: webSocketRPC, fn: webSocketRPC.Call}, `${service}.${method}`, args);
@ -31,10 +28,7 @@ export class AsyncRequest implements SagaWatcher {
} catch (e) { } catch (e) {
yield put(AsyncRequestActions.requestFailure(requestType, e)); yield put(AsyncRequestActions.requestFailure(requestType, e));
} finally { } finally {
// yield put({ yield put(AppAsyncRequestSendingActions.sending(true));
// type: types.SENDING_REQUEST,
// payload: {sendingRequest: false},
// });
} }
} }

View File

@ -0,0 +1,9 @@
export interface State {
complete: boolean;
}
export const defaultState: State = {
complete: false,
};
export default State;

View File

@ -2,9 +2,8 @@ import Action from '@overflow/commons/redux/Action';
import AsyncRequestPayload from '../payload/AsyncRequestPayload'; import AsyncRequestPayload from '../payload/AsyncRequestPayload';
// Action Type // Action Type
export type REQUEST = '@@overflow/anync/REQUEST'; export type REQUEST = '@overflow/commons/anync/REQUEST';
export const REQUEST: REQUEST = '@overflow/commons/anync/REQUEST';
export const REQUEST: REQUEST = '@@overflow/anync/REQUEST';
// Action Creater // Action Creater
export type request = (service: string, method: string, requestType: string, ...args: any[]) => Action<AsyncRequestPayload>; export type request = (service: string, method: string, requestType: string, ...args: any[]) => Action<AsyncRequestPayload>;