This commit is contained in:
crusader 2017-07-19 19:41:50 +09:00
parent c2e92ac3e1
commit bddfa41094
5 changed files with 38 additions and 8 deletions

View File

@ -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<RouteComponentProps<object>, object> {
@inject()
private client: WebSocketRPC;
public constructor(props?: RouteComponentProps<object>, context?: object) {
super(props, context);
let con = AppContext.get<WebSocketRPC>();
}
public render(): JSX.Element {
return (
<SignInContainer/>

View File

@ -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) {

View File

@ -1,15 +1,17 @@
import * as METADATA from '../constants';
export interface Config {
qualifier?: string;
required?: boolean;
}
const inject = <TFunction extends Function>(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);
}
};

View File

@ -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 <TFunction extends Function>(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;

View File

@ -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>(): T {
return null;
}
public static getContext(): AppContext {
if (null === AppContext.context) {
AppContext.context = new AppContext();
}
return AppContext.context;
}
}