diff --git a/src/ts/@overflow/app/views/member/SignIn.tsx b/src/ts/@overflow/app/views/member/SignIn.tsx index b7e8caa..7fc5141 100644 --- a/src/ts/@overflow/app/views/member/SignIn.tsx +++ b/src/ts/@overflow/app/views/member/SignIn.tsx @@ -2,12 +2,19 @@ import * as React from 'react'; import { RouteComponentProps } from 'react-router'; import SignInContainer from '@overflow/member/react/SignIn'; import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC'; +import AppContext from '@overflow/commons/context'; import inject from '@overflow/commons/context/decorator/inject'; class Signin extends React.Component, object> { @inject() private client: WebSocketRPC; + public constructor(props?: RouteComponentProps, context?: object) { + super(props, context); + + let con = AppContext.get(); + } + public render(): JSX.Element { return ( diff --git a/src/ts/@overflow/commons/api/Service.ts b/src/ts/@overflow/commons/api/Service.ts index cb8e7c1..c181b1d 100644 --- a/src/ts/@overflow/commons/api/Service.ts +++ b/src/ts/@overflow/commons/api/Service.ts @@ -2,7 +2,7 @@ import inject from '../context/decorator/inject'; import WebSocketRPC from '../websocket/WebSocketRPC'; abstract class Service { - @inject(WebSocketRPC) + @inject() private webSocketRPC: WebSocketRPC; private name: string; protected constructor(name: string) { diff --git a/src/ts/@overflow/commons/context/decorator/inject.ts b/src/ts/@overflow/commons/context/decorator/inject.ts index f60deb6..8c3da12 100644 --- a/src/ts/@overflow/commons/context/decorator/inject.ts +++ b/src/ts/@overflow/commons/context/decorator/inject.ts @@ -1,15 +1,17 @@ import * as METADATA from '../constants'; +export interface Config { + qualifier?: string; + required?: boolean; +} -const inject = (type?: TFunction) => { +const inject = (config?: Config) => { return (target: Object, propertyKey: string | symbol, parameterIndex?: number): void => { if (typeof parameterIndex === 'number') { // tagParameter(target, targetKey, index, metadata); } else { let types = Reflect.getMetadata('design:type', target, propertyKey); - let aaa = type; - console.log(aaa); // tagProperty(target, targetKey, metadata); } }; diff --git a/src/ts/@overflow/commons/context/decorator/injectable.ts b/src/ts/@overflow/commons/context/decorator/injectable.ts index 6af70b8..eac4cef 100644 --- a/src/ts/@overflow/commons/context/decorator/injectable.ts +++ b/src/ts/@overflow/commons/context/decorator/injectable.ts @@ -1,17 +1,29 @@ import * as METADATA from '../constants'; -function injectable(): ClassDecorator { +export interface Config { + qualifier?: string; + scope?: Scope; +} + +export enum Scope { + SINGLETON = 1, + PROTOTYPE, +} + +const injectable = (config?: Config) => { 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) || []; + let types = Reflect.getMetadata(METADATA.DESIGN_PARAM_TYPES, target); Reflect.defineMetadata(METADATA.PARAM_TYPES, types, target); + const name = target.name; + return target; }; -} +}; export default injectable; diff --git a/src/ts/@overflow/commons/context/index.ts b/src/ts/@overflow/commons/context/index.ts index a49a233..9d4f7d1 100644 --- a/src/ts/@overflow/commons/context/index.ts +++ b/src/ts/@overflow/commons/context/index.ts @@ -1,5 +1,5 @@ class AppContext { - private static context: AppContext; + private static context: AppContext = null; private constructor() { @@ -9,7 +9,16 @@ class AppContext { return null; } + public static get(): T { + + + return null; + } + public static getContext(): AppContext { + if (null === AppContext.context) { + AppContext.context = new AppContext(); + } return AppContext.context; } }