From 5a6d350a8ec1373be986ff9d63cc0d5566ac6d63 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 27 Sep 2017 18:33:10 +0900 Subject: [PATCH] Invoker --- src/semantic-ui/index.js | 5 + src/semantic-ui/semantic.less | 12 +++ .../site/elements/button.variables | 6 ++ src/semantic-ui/theme.config | 95 +++++++++++++++++++ src/ts/@overflow/app/config/index.ts | 11 ++- src/ts/@overflow/app/index.tsx | 3 + .../@overflow/commons/api/service/Service.ts | 5 + src/ts/@overflow/commons/api/service/index.ts | 1 + .../commons/invoke/ServiceInvoker.ts | 20 +++- .../commons/websocket/WebSocketRPC.ts | 8 +- .../discovery/api/service/DiscoveryService.ts | 7 +- 11 files changed, 164 insertions(+), 9 deletions(-) create mode 100644 src/semantic-ui/index.js create mode 100644 src/semantic-ui/semantic.less create mode 100644 src/semantic-ui/site/elements/button.variables create mode 100644 src/semantic-ui/theme.config create mode 100644 src/ts/@overflow/commons/api/service/Service.ts create mode 100644 src/ts/@overflow/commons/api/service/index.ts diff --git a/src/semantic-ui/index.js b/src/semantic-ui/index.js new file mode 100644 index 0000000..501500d --- /dev/null +++ b/src/semantic-ui/index.js @@ -0,0 +1,5 @@ +// this would bundle all Semantic components +require("semantic-ui-less/semantic.less"); + +// this would bundle only our selected components through our local semantic.less file +// require("./semantic.less"); \ No newline at end of file diff --git a/src/semantic-ui/semantic.less b/src/semantic-ui/semantic.less new file mode 100644 index 0000000..2a772a4 --- /dev/null +++ b/src/semantic-ui/semantic.less @@ -0,0 +1,12 @@ +/* We will be keeping the globals and 2 components: Button and Breadcrumbs */ + + +/* Global */ +& { @import "~semantic-ui-less/definitions/globals/reset"; } +& { @import "~semantic-ui-less/definitions/globals/site"; } + +/* Elements */ +& { @import "~semantic-ui-less/definitions/elements/button"; } + +/* Collections */ +& { @import "~semantic-ui-less/definitions/collections/breadcrumb"; } \ No newline at end of file diff --git a/src/semantic-ui/site/elements/button.variables b/src/semantic-ui/site/elements/button.variables new file mode 100644 index 0000000..3cc389e --- /dev/null +++ b/src/semantic-ui/site/elements/button.variables @@ -0,0 +1,6 @@ +@backgroundColor: #aeaeae; + +@primaryColor: #A05595; +@secondaryColor: #1C9BD5; + +@fontWeight: normal; \ No newline at end of file diff --git a/src/semantic-ui/theme.config b/src/semantic-ui/theme.config new file mode 100644 index 0000000..58be2db --- /dev/null +++ b/src/semantic-ui/theme.config @@ -0,0 +1,95 @@ +/* + +████████╗██╗ ██╗███████╗███╗ ███╗███████╗███████╗ +╚══██╔══╝██║ ██║██╔════╝████╗ ████║██╔════╝██╔════╝ + ██║ ███████║█████╗ ██╔████╔██║█████╗ ███████╗ + ██║ ██╔══██║██╔══╝ ██║╚██╔╝██║██╔══╝ ╚════██║ + ██║ ██║ ██║███████╗██║ ╚═╝ ██║███████╗███████║ + ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ + +*/ + +/******************************* + Theme Selection +*******************************/ + +/* To override a theme for an individual element + specify theme name below +*/ + +/* Global */ +@site : 'default'; +@reset : 'default'; + +/* Elements */ +@button : 'default'; +@container : 'default'; +@divider : 'default'; +@flag : 'default'; +@header : 'default'; +@icon : 'default'; +@image : 'default'; +@input : 'default'; +@label : 'default'; +@list : 'default'; +@loader : 'default'; +@rail : 'default'; +@reveal : 'default'; +@segment : 'default'; +@step : 'default'; + +/* Collections */ +@breadcrumb : 'default'; +@form : 'default'; +@grid : 'default'; +@menu : 'default'; +@message : 'default'; +@table : 'default'; + +/* Modules */ +@accordion : 'default'; +@checkbox : 'default'; +@dimmer : 'default'; +@dropdown : 'default'; +@embed : 'default'; +@modal : 'default'; +@nag : 'default'; +@popup : 'default'; +@progress : 'default'; +@rating : 'default'; +@search : 'default'; +@shape : 'default'; +@sidebar : 'default'; +@sticky : 'default'; +@tab : 'default'; +@transition : 'default'; + +/* Views */ +@ad : 'default'; +@card : 'default'; +@comment : 'default'; +@feed : 'default'; +@item : 'default'; +@statistic : 'default'; + +/******************************* + Folders +*******************************/ + +/* Path to theme packages */ +@themesFolder : 'themes'; + +/* Path to site override folder */ +@siteFolder : "./site"; + + +/******************************* + Import Theme +*******************************/ + +@import "~semantic-ui-less/theme.less"; +/* +@fontPath : "../../../themes/@{theme}/assets/fonts"; +*/ + +/* End Config */ \ No newline at end of file diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 4bdf67f..89c6a10 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -1,6 +1,8 @@ import { ReducersMapObject } from 'redux'; import SagaWatcher from '@overflow/commons/redux/saga/SagaWatcher'; +import { Service as APIService } from '@overflow/commons/api/service'; + import signInReducer from '@overflow/member/redux/reducer/signIn'; import signUpReducer from '@overflow/member/redux/reducer/signUp'; import modifyMemberReducer from '@overflow/member/redux/reducer/modify'; @@ -57,6 +59,8 @@ import AuthCrawlerRegistReducer from '@overflow/auth/redux/reducer/regist'; import AsyncRequest from '@overflow/app/redux/saga/AsyncRequest'; import AsyncRestRequest from '@overflow/app/redux/saga/AsyncRestRequest'; +import DiscoveryService from '@overflow/discovery/api/service/DiscoveryService'; + // Container Configuration export interface ContainerConfig { placeholderID: string; @@ -70,7 +74,7 @@ export interface RPCConfig { url: string; } const rpcConfig: RPCConfig = { - url: 'ws://192.168.1.209:19090/web', + url: 'ws://192.168.1.101:19090/web', }; // REST Server Configuration @@ -143,6 +147,9 @@ const reduxConfig: ReduxConfig = { ], }; +const serviceConfig: Map = new Map([ + ['DiscoveryService', DiscoveryService], +]); // Configuration export interface Config { @@ -150,6 +157,7 @@ export interface Config { rpc: RPCConfig; rest: RestConfig; redux: ReduxConfig; + service: Map; } const config: Config = { @@ -157,6 +165,7 @@ const config: Config = { rpc: rpcConfig, rest: restConfig, redux: reduxConfig, + service: serviceConfig, }; export default config; diff --git a/src/ts/@overflow/app/index.tsx b/src/ts/@overflow/app/index.tsx index 0e17f7c..bf5e52f 100644 --- a/src/ts/@overflow/app/index.tsx +++ b/src/ts/@overflow/app/index.tsx @@ -47,6 +47,8 @@ import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC'; import ReducerContext from '@overflow/commons/redux/ReducerContext'; import SagaWatcher from '@overflow/commons/redux/saga/SagaWatcher'; +import ServiceInvoker from '@overflow/commons/invoke/ServiceInvoker'; + import appConfig, { Config, ReduxState } from './config'; @@ -105,6 +107,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); client.initialize() .then(() => { diff --git a/src/ts/@overflow/commons/api/service/Service.ts b/src/ts/@overflow/commons/api/service/Service.ts new file mode 100644 index 0000000..3a6b54e --- /dev/null +++ b/src/ts/@overflow/commons/api/service/Service.ts @@ -0,0 +1,5 @@ +export abstract class Service { + +} + +export default Service; diff --git a/src/ts/@overflow/commons/api/service/index.ts b/src/ts/@overflow/commons/api/service/index.ts new file mode 100644 index 0000000..91cd426 --- /dev/null +++ b/src/ts/@overflow/commons/api/service/index.ts @@ -0,0 +1 @@ +export * from './Service'; diff --git a/src/ts/@overflow/commons/invoke/ServiceInvoker.ts b/src/ts/@overflow/commons/invoke/ServiceInvoker.ts index b059dc7..fe1bf2e 100644 --- a/src/ts/@overflow/commons/invoke/ServiceInvoker.ts +++ b/src/ts/@overflow/commons/invoke/ServiceInvoker.ts @@ -1,13 +1,24 @@ +import {Service} from '@overflow/commons/api/service'; + export class ServiceInvoker { + private config: Map; + private instanceMap: Map; - private configMap: Map; + public constructor(config: Map) { + this.config = config; + this.instanceMap = new Map(); - public constructor() { - this.configMap = new Map(); + this.initialize(); + } + + private initialize(): void { + this.config.forEach((value, key) => { + this.instanceMap.set(key, Object.create(value)); + }); } public invoke(className: string, methodName: string, params?: any): void { - let classObj: Object = this.configMap.get(className); + let classObj: Object = this.instanceMap.get(className); if (classObj === null || classObj === undefined) { console.log('Error: Cannot find the class. [' + className + ']'); return; @@ -21,3 +32,4 @@ export class ServiceInvoker { } +export default ServiceInvoker; diff --git a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts index 3b21447..e9f557b 100644 --- a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts +++ b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts @@ -44,13 +44,16 @@ export default class WebSocketRPC { private requestQueue: Map; + private serviceInvoker: ServiceInvoker; + /** * name */ - public constructor(url: string) { + public constructor(url: string, serviceInvoker: ServiceInvoker) { this.isReady = false; this.connStatus = WebSocketStatus.NOT_CONNECT; this.url = url; + this.serviceInvoker = serviceInvoker; this.onResponseListeners = new Map(); this.requestQueue = new Map(); } @@ -195,8 +198,7 @@ export default class WebSocketRPC { let className = methodArr[0]; let methodName = methodArr[1]; - let serviceInvoker: ServiceInvoker = new ServiceInvoker(); - serviceInvoker.invoke(className, methodName, notification.Params); + this.serviceInvoker.invoke(className, methodName, notification.Params); } private fireOnDisconnect(): void { diff --git a/src/ts/@overflow/discovery/api/service/DiscoveryService.ts b/src/ts/@overflow/discovery/api/service/DiscoveryService.ts index 95fa6d0..4576bc1 100644 --- a/src/ts/@overflow/discovery/api/service/DiscoveryService.ts +++ b/src/ts/@overflow/discovery/api/service/DiscoveryService.ts @@ -1,7 +1,10 @@ +import { Service } from '@overflow/commons/api/service'; -export class DiscoveryService { + +export class DiscoveryService extends Service { // tslint:disable-next-line:no-empty public constructor() { + super(); } public done(): void { @@ -10,3 +13,5 @@ export class DiscoveryService { } } + +export default DiscoveryService;