From de3a771eedc0a11c1bc6153f6bd29c76f46c5157 Mon Sep 17 00:00:00 2001 From: Byung Jun Park Date: Mon, 17 Jul 2017 23:38:00 +0900 Subject: [PATCH] ing --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/ts/.DS_Store | Bin 0 -> 6148 bytes src/ts/@overflow/.DS_Store | Bin 0 -> 8196 bytes src/ts/@overflow/app/index.tsx | 1 - src/ts/@overflow/app/redux/saga/client.ts | 20 +- src/ts/@overflow/app/router/index.tsx | 2 +- src/ts/@overflow/app/theme/mui.ts | 25 -- src/ts/@overflow/commons/api/Client.ts | 260 ------------------ src/ts/@overflow/commons/context/constants.ts | 8 + src/ts/@overflow/commons/context/index.ts | 17 ++ src/ts/@overflow/commons/context/inject.ts | 15 + .../@overflow/commons/context/injectable.ts | 16 ++ .../member/api/service/MemberService.ts | 4 +- tsconfig.json | 8 +- 15 files changed, 71 insertions(+), 305 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/ts/.DS_Store create mode 100644 src/ts/@overflow/.DS_Store delete mode 100644 src/ts/@overflow/app/theme/mui.ts delete mode 100644 src/ts/@overflow/commons/api/Client.ts create mode 100644 src/ts/@overflow/commons/context/constants.ts create mode 100644 src/ts/@overflow/commons/context/index.ts create mode 100644 src/ts/@overflow/commons/context/inject.ts create mode 100644 src/ts/@overflow/commons/context/injectable.ts diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f086ada34d8623b9566fd51e57cc8c6f02eb8a46 GIT binary patch literal 6148 zcmeHK%}T>S5Z<*_Q$*}Ru*bc4>mjwRJqaP!gEt|f2bDIl#Rh6plGLCvlGo5T@(Fw$ zXLh&JVh^4~>?zZ~e7vZHYZZ=mS%9-Jr`hru0;%%W#e zgv0S5Z-O8rihq>V2^w8)2QQT?8=G53wQ5v%jN9HQn)ebnnZ=Gfy_Qzs4?V44 zMA7(5cfHGCIPaT#CsCNVK{%W)gx_2Rp&!kiXcqdhoafw4MvyBP>YKGRZMR!>(X1DSggfUKP6>$d|IKv4A&FWN{C@X*iC;JFtt`B8HF{ zAO?s5VqonU&_{u>y>^vT!NdSD@Dl^LKL}`uw#Hnc+&ZAc>ofW*h$x`rTLMvNv^C}m z!2`loDxgZ``ia3+I*bb)XKTzAs&vNX$}o>!xp=&AxjKvs8P2$^ka}W(7+7YYtV|Qn z|5Ny7RzC8VQ^+C)h=G5`0Izg=T?dNNXY04}@T?Wk2GCG2E=L6f^rcGx7`Ttrq*M6? b>JVpZ%oXA+I4;ux=^`Krp^g~%1qMC=M>$Uc literal 0 HcmV?d00001 diff --git a/src/ts/.DS_Store b/src/ts/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..29801a3099a068c7d5ab6afeaa05bfb5b277739d GIT binary patch literal 6148 zcmeHK%}N6?5T3MEcM-7%!5(w*)MhK2<82*g<#}ck@nl<4~np5U1VVRQlz4oJJ~dszDm{^*AR%c89fk zqE59o9PaLVb?G&{QC$xA_ZxM&dsS1>XI%m6d6pbXgK&RJd1_3^Tp0cPO$4AA)?Q3-vEg+YCEU_-x; z6t57HpiOTHLTS;rSQx|ziZG>!rc~G`hA`#mmp0G0SQs?rAoR>Qj-6T97mCocqhIQD z5WYcfnE_^CmVvVAR_Xpf`uY7oTf{wPfEidQ21KRRZZ&a9_HLb99No1N^%|9g@(P2K k5;XKxjJb3b*HE>fUy_07TPzHs2ZetGG!5J^1AofE7snt|pa1{> literal 0 HcmV?d00001 diff --git a/src/ts/@overflow/.DS_Store b/src/ts/@overflow/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d9d04f9bce7ea9f5788f2c2a9011653831485a6f GIT binary patch literal 8196 zcmeHMU2GLa6rS(4g;m2TYbUhnR` zrIcb#d=fN1X+RB8U;KL%j6NBCk!WJXs*&(wOi&;60TU%LCZ5^ZTlzzdFPJ9mBr|7b z&N*}Doc(6z&RoVAk~w2DW0j0Ci880ELd7i-=kq)##loIqq9A?dWm2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N+4 zV1Yyc#qB-qNt(=jn=ij>$0;AB%oCTJ5HwJsV#Y%NwWt0tq { } function* read(socket: WebSocket): SagaIterator { - const channel = yield call(subscribe, socket); - let action = yield takeEvery(channel, (action: A) => any); - while (true) { - let action = yield take(channel); - yield put(action); - } + // const channel = yield call(subscribe, socket); + // let action = yield takeEvery(channel, (action: A) => any); + // while (true) { + // let action = yield take(channel); + // yield put(action); + // } } function* write(socket: WebSocket): SagaIterator { - while (true) { - const { payload } = yield take(`${sendMessage}`); - socket.emit('message', payload); - } + // while (true) { + // const { payload } = yield take(`${sendMessage}`); + // socket.emit('message', payload); + // } } function* flow(): SagaIterator { diff --git a/src/ts/@overflow/app/router/index.tsx b/src/ts/@overflow/app/router/index.tsx index 06d23d8..89683a9 100644 --- a/src/ts/@overflow/app/router/index.tsx +++ b/src/ts/@overflow/app/router/index.tsx @@ -7,7 +7,7 @@ const routes = ( - + ); diff --git a/src/ts/@overflow/app/theme/mui.ts b/src/ts/@overflow/app/theme/mui.ts deleted file mode 100644 index 7e890fd..0000000 --- a/src/ts/@overflow/app/theme/mui.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { colors, getMuiTheme, MuiTheme, spacing } from 'material-ui/styles'; -import { fade } from 'material-ui/utils/colorManipulator'; - -const muiTheme:MuiTheme = getMuiTheme({ - spacing: spacing, - fontFamily: 'Roboto, sans-serif', - palette: { - primary1Color: colors.cyan500, - primary2Color: colors.cyan700, - primary3Color: colors.grey400, - accent1Color: colors.pinkA200, - accent2Color: colors.grey100, - accent3Color: colors.grey500, - textColor: colors.darkBlack, - alternateTextColor: colors.white, - canvasColor: colors.white, - borderColor: colors.grey300, - disabledColor: fade(colors.darkBlack, 0.3), - pickerHeaderColor: colors.cyan500, - clockCircleColor: fade(colors.darkBlack, 0.07), - shadowColor: colors.fullBlack, - }, -}); - -export default muiTheme; diff --git a/src/ts/@overflow/commons/api/Client.ts b/src/ts/@overflow/commons/api/Client.ts deleted file mode 100644 index 106c8dd..0000000 --- a/src/ts/@overflow/commons/api/Client.ts +++ /dev/null @@ -1,260 +0,0 @@ -import * as io from 'socket.io-client'; - -export type OnConnectFunc = () => void; -export type OnWebsocketDisconnectFunc = () => void; -export type OnWebsocketNativeMessageFunc = (websocketMessage: string) => void; -export type OnMessageFunc = (message: any) => void; - -enum MessageType { - STRING = 1, - INT, - BOOLEAN, - JSON, -} - - - -class Client { - private conn: WebSocket; - private isReady: boolean; - - // events listeners - private connectListeners: OnConnectFunc[] = []; - private disconnectListeners: OnWebsocketDisconnectFunc[] = []; - private nativeMessageListeners: OnWebsocketNativeMessageFunc[] = []; - private messageListeners: { [event: string]: OnMessageFunc[] } = {}; - - constructor(endpoint: string, protocols?: string[]) { - // if (!window.WebSocket) { - // return; - // } - - if (endpoint.indexOf('ws') === -1) { - endpoint = 'ws://' + endpoint; - } - - if (protocols != null && protocols.length > 0) { - this.conn = new WebSocket(endpoint, protocols); - } else { - this.conn = new WebSocket(endpoint); - } - - this.conn.onopen = ((evt: Event): any => { - this.fireConnect(); - this.isReady = true; - return null; - }); - - this.conn.onclose = ((evt: Event): any => { - this.fireDisconnect(); - return null; - }); - - this.conn.onmessage = ((evt: MessageEvent) => { - this.messageReceivedFromConn(evt); - }); - - this.conn.onerror = ((evt: MessageEvent) => { - this.errorReceivedFromConn(evt); - }); - } - - public OnConnect(fn: OnConnectFunc): void { - if (this.isReady) { - fn(); - } - this.connectListeners.push(fn); - } - public OnDisconnect(fn: OnWebsocketDisconnectFunc): void { - this.disconnectListeners.push(fn); - } - public OnMessage(cb: OnWebsocketNativeMessageFunc): void { - this.nativeMessageListeners.push(cb); - } - public On(event: string, cb: OnMessageFunc): void { - if (this.messageListeners[event] == null || this.messageListeners[event] === undefined) { - this.messageListeners[event] = []; - } - this.messageListeners[event].push(cb); - } - - // - - // Ws Actions - public Disconnect(): void { - this.conn.close(); - } - - // EmitMessage sends a native websocket message - public EmitMessage(websocketMessage: string): void { - this.conn.send(websocketMessage); - } - - protected fireConnect(): void { - for (let i = 0; i < this.connectListeners.length; i++) { - this.connectListeners[i](); - } - } - - protected fireDisconnect(): void { - for (let i = 0; i < this.disconnectListeners.length; i++) { - this.disconnectListeners[i](); - } - } - - protected fireNativeMessage(websocketMessage: string): void { - for (let i = 0; i < this.nativeMessageListeners.length; i++) { - this.nativeMessageListeners[i](websocketMessage); - } - } - - protected fireMessage(event: string, message: any): void { - for (let key in this.messageListeners) { - if (this.messageListeners.hasOwnProperty(key)) { - if (key === event) { - for (let i = 0; i < this.messageListeners[key].length; i++) { - this.messageListeners[key][i](message); - } - } - } - } - } - - // utils - private isNumber(obj: any): boolean { - return !isNaN(obj - 0) && obj !== null && obj !== '' && obj !== false; - } - - private isString(obj: any): boolean { - return Object.prototype.toString.call(obj) === '[object String]'; - } - - private isBoolean(obj: any): boolean { - return typeof obj === 'boolean' || - (typeof obj === 'object' && typeof obj.valueOf() === 'boolean'); - } - - private isJSON(obj: any): boolean { - return typeof obj === 'object'; - } - - // - - // messages - private _msg(event: string, messageType: MessageType, dataMessage: string): string { - - return websocketMessagePrefix + event + websocketMessageSeparator + String(websocketMessageType) + websocketMessageSeparator + dataMessage; - } - - private encodeMessage(event: string, data: any): string { - let m = ''; - let t: MessageType = MessageType.STRING; - if (this.isNumber(data)) { - t = MessageType.INT; - m = data.toString(); - } else if (this.isBoolean(data)) { - t = MessageType.BOOLEAN; - m = data.toString(); - } else if (this.isString(data)) { - t = MessageType.STRING; - m = data.toString(); - } else if (this.isJSON(data)) { - // propably json-object - t = MessageType.JSON; - m = JSON.stringify(data); - } else { - console.log('Invalid, javascript-side should contains an empty second parameter.'); - } - - return this._msg(event, t, m); - } - - private decodeMessage(event: string, websocketMessage: string): T | any { - // q-websocket-message;user;4;themarshaledstringfromajsonstruct - let skipLen = websocketMessagePrefixLen + websocketMessageSeparatorLen + event.length + 2; - if (websocketMessage.length < skipLen + 1) { - return null; - } - let websocketMessageType = parseInt(websocketMessage.charAt(skipLen - 2)); - let theMessage = websocketMessage.substring(skipLen, websocketMessage.length); - if (websocketMessageType === MessageType.INT) { - return parseInt(theMessage); - } else if (websocketMessageType === MessageType.BOOLEAN) { - return Boolean(theMessage); - } else if (websocketMessageType === MessageType.STRING) { - return theMessage; - } else if (websocketMessageType === MessageType.JSON) { - return JSON.parse(theMessage); - } else { - return null; // invalid - } - } - - private getWebsocketCustomEvent(websocketMessage: string): string { - if (websocketMessage.length < websocketMessagePrefixAndSepIdx) { - return ''; - } - let s = websocketMessage.substring(websocketMessagePrefixAndSepIdx, websocketMessage.length); - let evt = s.substring(0, s.indexOf(websocketMessageSeparator)); - - return evt; - } - - private getCustomMessage(event: string, websocketMessage: string): string { - let eventIdx = websocketMessage.indexOf(event + websocketMessageSeparator); - let s = websocketMessage.substring(eventIdx + event.length + websocketMessageSeparator.length + 2, websocketMessage.length); - return s; - } - - // - - // Ws Events - - // messageReceivedFromConn this is the func which decides - // if it's a native websocket message or a custom qws message - // if native message then calls the fireNativeMessage - // else calls the fireMessage - // - // remember q gives you the freedom of native websocket messages if you don't want to use this client side at all. - private messageReceivedFromConn(evt: MessageEvent): void { - // check if qws message - let message = evt.data; - if (message.indexOf(websocketMessagePrefix) !== -1) { - let event = this.getWebsocketCustomEvent(message); - if (event !== '') { - // it's a custom message - this.fireMessage(event, this.getCustomMessage(event, message)); - return; - } - } - - // it's a native websocket message - this.fireNativeMessage(message); - } - - // errorReceivedFromConn this is the func which decides - // if it's a native websocket message or a custom qws message - // if native message then calls the fireNativeMessage - // else calls the fireMessage - // - // remember q gives you the freedom of native websocket messages if you don't want to use this client side at all. - private errorReceivedFromConn(evt: MessageEvent): void { - // check if qws message - let message = evt.data; - if (message.indexOf(websocketMessagePrefix) !== -1) { - let event = this.getWebsocketCustomEvent(message); - if (event !== '') { - // it's a custom message - this.fireMessage(event, this.getCustomMessage(event, message)); - return; - } - } - - // it's a native websocket message - this.fireNativeMessage(message); - } - -} - - -export default Client; diff --git a/src/ts/@overflow/commons/context/constants.ts b/src/ts/@overflow/commons/context/constants.ts new file mode 100644 index 0000000..e3a77ba --- /dev/null +++ b/src/ts/@overflow/commons/context/constants.ts @@ -0,0 +1,8 @@ +// used to store types to be injected +export const PARAM_TYPES = 'overflow:paramtypes'; + +// used to access design time types +export const DESIGN_PARAM_TYPES = 'design:paramtypes'; + +// The type of the binding at design time +export const INJECT_TAG = 'inject'; diff --git a/src/ts/@overflow/commons/context/index.ts b/src/ts/@overflow/commons/context/index.ts new file mode 100644 index 0000000..a49a233 --- /dev/null +++ b/src/ts/@overflow/commons/context/index.ts @@ -0,0 +1,17 @@ +class AppContext { + private static context: AppContext; + + private constructor() { + + } + + public static getService(): T { + return null; + } + + public static getContext(): AppContext { + return AppContext.context; + } +} + +export default AppContext; diff --git a/src/ts/@overflow/commons/context/inject.ts b/src/ts/@overflow/commons/context/inject.ts new file mode 100644 index 0000000..86e984b --- /dev/null +++ b/src/ts/@overflow/commons/context/inject.ts @@ -0,0 +1,15 @@ + +import * as METADATA from './constants'; + + +function inject(): PropertyDecorator | ParameterDecorator { + return (target: Object, propertyKey: string | symbol, parameterIndex?: number): void => { + let metadata = new Metadata(METADATA.INJECT_TAG, serviceIdentifier); + + if (typeof parameterIndex === 'number') { + tagParameter(target, propertyKey, parameterIndex, metadata); + } else { + tagProperty(target, propertyKey, metadata); + } + }; +} diff --git a/src/ts/@overflow/commons/context/injectable.ts b/src/ts/@overflow/commons/context/injectable.ts new file mode 100644 index 0000000..e0cdca3 --- /dev/null +++ b/src/ts/@overflow/commons/context/injectable.ts @@ -0,0 +1,16 @@ +import * as METADATA from './constants'; + +function injectable(): ClassDecorator { + return (target: TFunction): TFunction | void => { + + if (Reflect.hasOwnMetadata(METADATA.PARAM_TYPES, target) === true) { + throw new Error('Cannot apply @injectable decorator multiple times.'); + } + + let types = Reflect.getMetadata(METADATA.DESIGN_PARAM_TYPES, target) || []; + Reflect.defineMetadata(METADATA.PARAM_TYPES, types, target); + + return target; + }; +} + diff --git a/src/ts/@overflow/member/api/service/MemberService.ts b/src/ts/@overflow/member/api/service/MemberService.ts index fff644a..fe7fb06 100644 --- a/src/ts/@overflow/member/api/service/MemberService.ts +++ b/src/ts/@overflow/member/api/service/MemberService.ts @@ -1,6 +1,8 @@ import Service from '@overflow/commons/api/Service'; import Member from '../model/Member'; -import service from '@overflow/commons/context/decorator/service'; +// import service from '@overflow/commons/context/decorator/service'; + + @service() export class MemberService extends Service { diff --git a/tsconfig.json b/tsconfig.json index 7c0c318..bc72581 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "allowSyntheticDefaultImports": true, - "baseUrl": ".", + "baseUrl": "./src/ts", "declaration": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, @@ -18,12 +18,6 @@ "outDir": "dist/ts/", "preserveConstEnums": true, "pretty": true, - "paths": { - "*": [ - "./src/ts/*", - "./types/*" - ] - }, "removeComments": true, "sourceMap": true, "target": "es5",