This commit is contained in:
crusader 2017-09-27 19:32:25 +09:00
parent 61597d4581
commit 5f63a0b4de
6 changed files with 41 additions and 11 deletions

View File

@ -152,6 +152,7 @@ const serviceConfig: Map<string, APIService> = new Map();
serviceConfig.set('DiscoveryService', DiscoveryService.prototype);
serviceConfig.set('NoAuthProbeService', NoAuthProbeService.prototype);
// Configuration
export interface Config {
container: ContainerConfig;

View File

@ -77,7 +77,6 @@ class OFApplication {
private sagaMiddleware: SagaMiddleware<any>;
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<WebSocketRPC> {
const rpcClient = new Promise<WebSocketRPC>((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);

View File

@ -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<any>;
protected dispatch(action: Action<any>): void {
this.store.dispatch(action);
}
public setStore(store: Store<any>): void {
this.store = store;
}
}
export default Service;

View File

@ -1,11 +1,16 @@
import {Service} from '@overflow/commons/api/service';
import {
Store,
} from 'redux';
export class ServiceInvoker {
private config: Map<string, Service>;
private instanceMap: Map<string, Object>;
private store: Store<any>;
public constructor(config: Map<string, Service>) {
public constructor(config: Map<string, Service>, store: Store<any>) {
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);
});
}

View File

@ -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<any> {
return new Promise<any>((resolve, reject) => {
const requestID = this.getRequestID();

View File

@ -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);
}
}