AsyncNotify have been added.
This commit is contained in:
parent
5f63a0b4de
commit
a57a934782
|
@ -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,
|
||||
],
|
||||
};
|
||||
|
|
29
src/ts/@overflow/app/redux/saga/AsyncNotify.ts
Normal file
29
src/ts/@overflow/app/redux/saga/AsyncNotify.ts
Normal 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;
|
|
@ -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;
|
||||
|
|
20
src/ts/@overflow/commons/redux/action/asyncNotify.ts
Normal file
20
src/ts/@overflow/commons/redux/action/asyncNotify.ts
Normal 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,
|
||||
},
|
||||
};
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
import Action from '@overflow/commons/redux/Action';
|
||||
|
||||
interface AsyncNotifyPayload {
|
||||
service: string;
|
||||
method: string;
|
||||
args?: any[];
|
||||
}
|
||||
|
||||
export default AsyncNotifyPayload;
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user