AsyncNotify have been added.

This commit is contained in:
crusader 2017-09-27 19:57:28 +09:00
parent 5f63a0b4de
commit a57a934782
7 changed files with 77 additions and 6 deletions

View File

@ -57,6 +57,7 @@ import ForgotPassword from '@overflow/member/redux/reducer/forgotPassword';
import AuthCrawlerRegistReducer from '@overflow/auth/redux/reducer/regist';
import AsyncRequest from '@overflow/app/redux/saga/AsyncRequest';
import AsyncNotify from '@overflow/app/redux/saga/AsyncNotify';
import AsyncRestRequest from '@overflow/app/redux/saga/AsyncRestRequest';
import DiscoveryService from '@overflow/discovery/api/service/DiscoveryService';
@ -144,6 +145,7 @@ const reduxConfig: ReduxConfig = {
],
sagaWatchers: [
AsyncRequest,
AsyncNotify,
AsyncRestRequest,
],
};

View File

@ -0,0 +1,29 @@
import { SagaIterator } from 'redux-saga';
import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects';
import Action from '@overflow/commons/redux/Action';
import SagaWatcher from '@overflow/commons/redux/saga/SagaWatcher';
import * as AsyncNotifyActions from '@overflow/commons/redux/action/asyncNotify';
import AsyncNotifyPayload from '@overflow/commons/redux/payload/AsyncNotifyPayload';
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
export class AsyncNotify implements SagaWatcher {
private _webSocketRPC: WebSocketRPC;
public setWebSocketRPC(webSocketRPC: WebSocketRPC): void {
this._webSocketRPC = webSocketRPC;
}
private * request(webSocketRPC: WebSocketRPC, action: Action<AsyncNotifyPayload>): SagaIterator {
const {service, method, args} = action.payload;
yield call({context: webSocketRPC, fn: webSocketRPC.Notify}, `${service}.${method}`, args);
}
public * watch(): SagaIterator {
yield takeEvery(AsyncNotifyActions.NOTIFY, this.request, this._webSocketRPC);
}
}
export default AsyncNotify;

View File

@ -7,13 +7,18 @@ import Action from '@overflow/commons/redux/Action';
export abstract class Service {
private store: Store<any>;
protected dispatch(action: Action<any>): void {
this.store.dispatch(action);
}
public setStore(store: Store<any>): void {
this.store = store;
}
protected dispatch(actionType: any, payload?: any): void {
const action: Action = {
type: actionType,
payload: payload,
};
this.store.dispatch(action);
}
}
export default Service;

View File

@ -0,0 +1,20 @@
import Action from '@overflow/commons/redux/Action';
import AsyncNotifyPayload from '../payload/AsyncNotifyPayload';
// Action Type
export type NOTIFY = '@overflow/commons/async/notify/NOTIFY';
export const NOTIFY: NOTIFY = '@overflow/commons/async/notify/NOTIFY';
// Action Creater
export type notify = (service: string, method: string, ...args: any[]) => Action<AsyncNotifyPayload>;
export const notify: notify = (service: string, method: string, ...args: any[]): Action<AsyncNotifyPayload> => {
return {
type: NOTIFY,
payload: {
service: service,
method: method,
args: args,
},
};
};

View File

@ -0,0 +1,9 @@
import Action from '@overflow/commons/redux/Action';
interface AsyncNotifyPayload {
service: string;
method: string;
args?: any[];
}
export default AsyncNotifyPayload;

View File

@ -72,6 +72,12 @@ export default class WebSocketRPC {
});
}
public Notify(method: string, args: any): void {
let notification = new Notification(method, args);
notification.Protocol = PROTOCOL_NAME;
this.conn.send(JSON.stringify(notification));
}
public OnDisconnect(cb: OnDisconnectFunc): void {
this.onDisconnectListeners.push(cb);
}

View File

@ -9,11 +9,11 @@ export class NoAuthProbeService extends Service {
}
public regist(params: any): void {
const json: NoAuthProbe = JSON.parse(params);
const noAuthProbe: NoAuthProbe = JSON.parse(params);
const action: Action = {
type: 'TEST',
};
this.dispatch(action);
this.dispatch('TEST', noAuthProbe);
}
}