From 5f63a0b4de8be2cde7d31f274d6bf760b4e91e14 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 27 Sep 2017 19:32:25 +0900 Subject: [PATCH] ing --- src/ts/@overflow/app/config/index.ts | 1 + src/ts/@overflow/app/index.tsx | 7 ++++--- src/ts/@overflow/commons/api/service/Service.ts | 16 +++++++++++++++- .../@overflow/commons/invoke/ServiceInvoker.ts | 11 +++++++++-- .../@overflow/commons/websocket/WebSocketRPC.ts | 7 +++++-- .../api/service/NoAuthProbeService.ts | 10 +++++++--- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 5dd6a97..19144e0 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -152,6 +152,7 @@ const serviceConfig: Map = new Map(); serviceConfig.set('DiscoveryService', DiscoveryService.prototype); serviceConfig.set('NoAuthProbeService', NoAuthProbeService.prototype); + // Configuration export interface Config { container: ContainerConfig; diff --git a/src/ts/@overflow/app/index.tsx b/src/ts/@overflow/app/index.tsx index 3b5954b..69c1d84 100644 --- a/src/ts/@overflow/app/index.tsx +++ b/src/ts/@overflow/app/index.tsx @@ -77,7 +77,6 @@ class OFApplication { private sagaMiddleware: SagaMiddleware; private history: History; - public constructor() { this.config = appConfig; this.history = createHashHistory(); @@ -98,6 +97,9 @@ class OFApplication { await this.initRedux(); + let serviceInvoker = new ServiceInvoker(this.config.service, this.store); + this.rpcClient.setServiceInvoker(serviceInvoker); + this.displayApp(); } catch (e) { console.error(e); @@ -107,8 +109,7 @@ class OFApplication { private initRpcClient(): Promise { const rpcClient = new Promise((resolve, reject) => { - let serviceInvoker = new ServiceInvoker(this.config.service); - let client = new WebSocketRPC(this.config.rpc.url, serviceInvoker); + let client = new WebSocketRPC(this.config.rpc.url); client.initialize() .then(() => { resolve(client); diff --git a/src/ts/@overflow/commons/api/service/Service.ts b/src/ts/@overflow/commons/api/service/Service.ts index 3a6b54e..926607f 100644 --- a/src/ts/@overflow/commons/api/service/Service.ts +++ b/src/ts/@overflow/commons/api/service/Service.ts @@ -1,5 +1,19 @@ -export abstract class Service { +import { + Store, +} from 'redux'; +import Action from '@overflow/commons/redux/Action'; + +export abstract class Service { + private store: Store; + + protected dispatch(action: Action): void { + this.store.dispatch(action); + } + + public setStore(store: Store): void { + this.store = store; + } } export default Service; diff --git a/src/ts/@overflow/commons/invoke/ServiceInvoker.ts b/src/ts/@overflow/commons/invoke/ServiceInvoker.ts index fe1bf2e..9e9c25e 100644 --- a/src/ts/@overflow/commons/invoke/ServiceInvoker.ts +++ b/src/ts/@overflow/commons/invoke/ServiceInvoker.ts @@ -1,11 +1,16 @@ import {Service} from '@overflow/commons/api/service'; +import { + Store, +} from 'redux'; export class ServiceInvoker { private config: Map; private instanceMap: Map; + private store: Store; - public constructor(config: Map) { + public constructor(config: Map, store: Store) { this.config = config; + this.store = store; this.instanceMap = new Map(); this.initialize(); @@ -13,7 +18,9 @@ export class ServiceInvoker { private initialize(): void { this.config.forEach((value, key) => { - this.instanceMap.set(key, Object.create(value)); + const instance: Service = Object.create(value); + instance.setStore(this.store); + this.instanceMap.set(key, instance); }); } diff --git a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts index e9f557b..39be84d 100644 --- a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts +++ b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts @@ -49,15 +49,18 @@ export default class WebSocketRPC { /** * name */ - public constructor(url: string, serviceInvoker: ServiceInvoker) { + public constructor(url: string) { this.isReady = false; this.connStatus = WebSocketStatus.NOT_CONNECT; this.url = url; - this.serviceInvoker = serviceInvoker; this.onResponseListeners = new Map(); this.requestQueue = new Map(); } + public setServiceInvoker(serviceInvoker: ServiceInvoker): void { + this.serviceInvoker = serviceInvoker; + } + public Call(method: string, args: any): Promise { return new Promise((resolve, reject) => { const requestID = this.getRequestID(); diff --git a/src/ts/@overflow/noauthprobe/api/service/NoAuthProbeService.ts b/src/ts/@overflow/noauthprobe/api/service/NoAuthProbeService.ts index cd2ca91..cb68d3d 100644 --- a/src/ts/@overflow/noauthprobe/api/service/NoAuthProbeService.ts +++ b/src/ts/@overflow/noauthprobe/api/service/NoAuthProbeService.ts @@ -1,5 +1,6 @@ import { Service } from '@overflow/commons/api/service'; - +import NoAuthProbe from '../model/NoAuthProbe'; +import Action from '@overflow/commons/redux/Action'; export class NoAuthProbeService extends Service { // tslint:disable-next-line:no-empty @@ -8,8 +9,11 @@ export class NoAuthProbeService extends Service { } public regist(params: any): void { - console.log('Discovery has finished.' + params); - // state change test + const json: NoAuthProbe = JSON.parse(params); + const action: Action = { + type: 'TEST', + }; + this.dispatch(action); } }