Merge branch 'master' of https://git.loafle.net/overflow/overflow_app
This commit is contained in:
commit
402adebb44
|
@ -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/>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user