Async Request
This commit is contained in:
parent
1c32a26e8b
commit
99724e10ce
18
src/ts/@overflow/app/redux/action/asyncRequestSending.ts
Normal file
18
src/ts/@overflow/app/redux/action/asyncRequestSending.ts
Normal 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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,5 @@
|
||||||
|
export interface AsyncRequestSendingPayload {
|
||||||
|
complete: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AsyncRequestSendingPayload;
|
20
src/ts/@overflow/app/redux/reducer/asyncRequestSending.ts
Normal file
20
src/ts/@overflow/app/redux/reducer/asyncRequestSending.ts
Normal 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;
|
|
@ -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},
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
src/ts/@overflow/app/redux/state/AsyncRequestSending.ts
Normal file
9
src/ts/@overflow/app/redux/state/AsyncRequestSending.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export interface State {
|
||||||
|
complete: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const defaultState: State = {
|
||||||
|
complete: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default State;
|
|
@ -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>;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user