ing
This commit is contained in:
parent
00583067cd
commit
d3d477d8d1
52
src/ts/@overflow/commons/application/application.ts
Normal file
52
src/ts/@overflow/commons/application/application.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import {
|
||||
Class,
|
||||
} from '@overflow/commons/core/reflect';
|
||||
import { ClassType } from '@overflow/commons/core/type';
|
||||
import { ApplicationContext } from './context';
|
||||
import {
|
||||
InjectableClass,
|
||||
InjectableFactory,
|
||||
InjectableValue,
|
||||
WebApplicationAnnotation,
|
||||
} from './decorators';
|
||||
|
||||
export class Application {
|
||||
private primaryClass: ClassType;
|
||||
private applicationContext: ApplicationContext;
|
||||
|
||||
public static run(primaryClass: ClassType): void {
|
||||
let app: Application = new Application(primaryClass);
|
||||
}
|
||||
|
||||
public constructor(primaryClass: ClassType) {
|
||||
this.primaryClass = primaryClass;
|
||||
|
||||
this.createContext();
|
||||
}
|
||||
|
||||
private createContext(): void {
|
||||
let clazz: Class = Class.forClass(this.primaryClass);
|
||||
|
||||
let wa: WebApplicationAnnotation = clazz.getOwnAnnotation(WebApplicationAnnotation);
|
||||
if (undefined === wa) {
|
||||
console.warn(`Class is not WebApplication type. add @WebApplication annotation to class[${this.primaryClass.name}]`);
|
||||
return;
|
||||
}
|
||||
|
||||
let context: ApplicationContext = new ApplicationContext();
|
||||
// context.registerInjectables(wa.attributes.injectables);
|
||||
|
||||
wa.attributes.injectables.forEach(injectable => {
|
||||
if (undefined !== (<InjectableClass>injectable).injectableType) {
|
||||
context.registerInjectable()
|
||||
} else if (undefined !== (<InjectableFactory>injectable).injectableFactory) {
|
||||
console.log(`InjectableFactory`);
|
||||
} else if (undefined !== (<InjectableValue>injectable).injectableValue) {
|
||||
console.log(`InjectableValue`);
|
||||
} else if (typeof injectable === 'function') {
|
||||
console.log(`Class`);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export class ApplicationContext {
|
||||
|
||||
}
|
1
src/ts/@overflow/commons/application/context/index.ts
Normal file
1
src/ts/@overflow/commons/application/context/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './application_context';
|
|
@ -0,0 +1,42 @@
|
|||
import {
|
||||
Annotation,
|
||||
Decorator,
|
||||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
ClassType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
export interface ConfigurationAnnotationAttributes {
|
||||
name?: string[];
|
||||
}
|
||||
|
||||
export class ConfigurationAnnotation implements Annotation {
|
||||
public readonly attributes: ConfigurationAnnotationAttributes;
|
||||
|
||||
public constructor(name: string | ConfigurationAnnotationAttributes) {
|
||||
|
||||
if (undefined === name) {
|
||||
this.attributes = {
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
if (TypeUtil.isString(name)) {
|
||||
this.attributes = {
|
||||
name: [<string>name],
|
||||
};
|
||||
} else {
|
||||
this.attributes = <ConfigurationAnnotationAttributes>name;
|
||||
}
|
||||
}
|
||||
|
||||
public classDecorator<TFunction extends Function>(target: TFunction): TFunction | void {
|
||||
// no op
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const Configuration = Decorator.create(ConfigurationAnnotation);
|
|
@ -1 +1,2 @@
|
|||
export * from './configuration';
|
||||
export * from './web_application';
|
||||
|
|
|
@ -5,14 +5,28 @@ import {
|
|||
|
||||
import {
|
||||
ClassType,
|
||||
MetadataKeyType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
export interface InjectableClass {
|
||||
injectType: ClassType;
|
||||
injectableType: ClassType;
|
||||
}
|
||||
|
||||
export interface InjectableFactory {
|
||||
injectType: ClassType;
|
||||
injectableFactory: (...params: any[]) => any;
|
||||
}
|
||||
|
||||
export interface InjectableValue {
|
||||
injectName: PropertyKeyType;
|
||||
injectableValue: any;
|
||||
}
|
||||
|
||||
export type InjectablesType = (ClassType | InjectableClass | InjectableFactory | InjectableValue)[];
|
||||
|
||||
export interface WebApplicationAnnotationAttributes {
|
||||
injectables?: ClassType[];
|
||||
injectables?: InjectablesType;
|
||||
configurations?: ClassType[];
|
||||
}
|
||||
|
||||
|
@ -24,7 +38,7 @@ export class WebApplicationAnnotation implements Annotation {
|
|||
}
|
||||
|
||||
public classDecorator<TFunction extends Function>(target: TFunction): TFunction | void {
|
||||
console.log('WebApplication');
|
||||
// no op
|
||||
}
|
||||
|
||||
}
|
||||
|
|
1
src/ts/@overflow/commons/application/index.ts
Normal file
1
src/ts/@overflow/commons/application/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './application';
|
|
@ -4,35 +4,36 @@ import {
|
|||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
MetadataKeyType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
|
||||
export interface InjectAnnotationAttributes {
|
||||
value: string[];
|
||||
name?: string[];
|
||||
}
|
||||
|
||||
export class InjectAnnotation implements Annotation {
|
||||
public readonly attributes: InjectAnnotationAttributes;
|
||||
|
||||
public constructor(value: string | string[] | InjectAnnotationAttributes) {
|
||||
public constructor(name: string | string[] | InjectAnnotationAttributes) {
|
||||
|
||||
if (undefined === value) {
|
||||
throw new Error(`value attribute must be specified.`);
|
||||
if (undefined === name) {
|
||||
this.attributes = {
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
if (TypeUtil.isString(value)) {
|
||||
if (TypeUtil.isString(name)) {
|
||||
this.attributes = {
|
||||
value: [<string>value],
|
||||
name: [<string>name],
|
||||
};
|
||||
} else if (TypeUtil.isArray(value)) {
|
||||
} else if (TypeUtil.isArray(name)) {
|
||||
this.attributes = {
|
||||
value: <string[]>value,
|
||||
name: <string[]>name,
|
||||
};
|
||||
} else {
|
||||
this.attributes = <InjectAnnotationAttributes>value;
|
||||
this.attributes = <InjectAnnotationAttributes>name;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,10 @@ import {
|
|||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
MetadataKeyType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
|
||||
export interface InjectableAnnotationAttributes {
|
||||
name?: string[];
|
||||
}
|
||||
|
@ -20,7 +18,9 @@ export class InjectableAnnotation implements Annotation {
|
|||
public constructor(name: string | string[] | InjectableAnnotationAttributes) {
|
||||
|
||||
if (undefined === name) {
|
||||
throw new Error(`value attribute must be specified.`);
|
||||
this.attributes = {
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
if (TypeUtil.isString(name)) {
|
||||
|
|
|
@ -4,35 +4,29 @@ import {
|
|||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
MetadataKeyType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
|
||||
export interface ResourceAnnotationAttributes {
|
||||
value: string[];
|
||||
name: string[];
|
||||
}
|
||||
|
||||
export class ResourceAnnotation implements Annotation {
|
||||
public readonly attributes: ResourceAnnotationAttributes;
|
||||
|
||||
public constructor(value: string | string[] | ResourceAnnotationAttributes) {
|
||||
public constructor(name: string | ResourceAnnotationAttributes) {
|
||||
|
||||
if (undefined === value) {
|
||||
throw new Error(`value attribute must be specified.`);
|
||||
if (undefined === name) {
|
||||
throw new Error(`name attribute must be specified.`);
|
||||
}
|
||||
|
||||
if (TypeUtil.isString(value)) {
|
||||
if (TypeUtil.isString(name)) {
|
||||
this.attributes = {
|
||||
value: [<string>value],
|
||||
};
|
||||
} else if (TypeUtil.isArray(value)) {
|
||||
this.attributes = {
|
||||
value: <string[]>value,
|
||||
name: [<string>name],
|
||||
};
|
||||
} else {
|
||||
this.attributes = <ResourceAnnotationAttributes>value;
|
||||
this.attributes = <ResourceAnnotationAttributes>name;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
src/ts/@overflow/commons/di/factory/instance_definition.ts
Normal file
14
src/ts/@overflow/commons/di/factory/instance_definition.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import {
|
||||
ClassType,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
export class InstanceDefinition {
|
||||
private _instanceClass: ClassType;
|
||||
|
||||
public get InstanceClass(): ClassType {
|
||||
return this._instanceClass;
|
||||
}
|
||||
public set InstanceClass(instanceClass: ClassType) {
|
||||
this._instanceClass = instanceClass;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
import { PropertyKeyType } from '@overflow/commons/core/type';
|
||||
|
||||
import { PropertyValue } from './property_value';
|
||||
|
||||
|
||||
|
||||
export class MutablePropertyValues {
|
||||
private propertyValueList: PropertyValue[];
|
||||
private processedProperties: Set<PropertyKeyType>;
|
||||
|
||||
public constructor(propertyValueList?: PropertyValue[]) {
|
||||
if (undefined === propertyValueList) {
|
||||
this.propertyValueList = [];
|
||||
} else {
|
||||
this.propertyValueList = propertyValueList;
|
||||
}
|
||||
}
|
||||
|
||||
public addPropertyValue(pv :PropertyValue): MutablePropertyValues {
|
||||
for (let i = 0; i < this.propertyValueList.length; i++) {
|
||||
let currentPv: PropertyValue = this.propertyValueList[i];
|
||||
if (currentPv.Name === pv.Name) {
|
||||
pv = mergeIfRequired(pv, currentPv);
|
||||
setPropertyValueAt(pv, i);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
this.propertyValueList.push(pv);
|
||||
return this;
|
||||
}
|
||||
}
|
18
src/ts/@overflow/commons/di/factory/property_value.ts
Normal file
18
src/ts/@overflow/commons/di/factory/property_value.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { PropertyKeyType } from '@overflow/commons/core/type';
|
||||
|
||||
export class PropertyValue {
|
||||
private readonly name: PropertyKeyType;
|
||||
private readonly value: any;
|
||||
|
||||
public constructor(name: PropertyKeyType, value: any) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public get Name(): PropertyKeyType {
|
||||
return this.name;
|
||||
}
|
||||
public get Value(): any {
|
||||
return this.value;
|
||||
}
|
||||
}
|
|
@ -4,12 +4,10 @@ import {
|
|||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
MetadataKeyType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
|
||||
export interface ActionMappingAnnotationAttributes {
|
||||
value: string[];
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
MetadataKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
MetadataKeyType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
} from '@overflow/commons/core/reflect';
|
||||
|
||||
import {
|
||||
MetadataKeyType,
|
||||
PropertyKeyType,
|
||||
TypeUtil,
|
||||
} from '@overflow/commons/core/type';
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
import { Class } from '@overflow/commons/core/reflect';
|
||||
import { Action } from './action';
|
||||
|
||||
export default class DispatchReducer {
|
||||
export class DispatcherReducer {
|
||||
|
||||
private reducerMap: Map<string, any[]>;
|
||||
|
2
src/ts/@overflow/commons/redux/index.ts
Normal file
2
src/ts/@overflow/commons/redux/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from './action';
|
||||
export * from './dispatcher_reducer';
|
|
@ -1,8 +1,14 @@
|
|||
import { ConstructorType } from '@overflow/commons/core/type';
|
||||
export * from './injectables';
|
||||
export * from './reducer_configuration';
|
||||
export * from './rest_api_configuration';
|
||||
export * from './rpc_api_configuration';
|
||||
export * from './webapp_configuration';
|
||||
|
||||
import { ClassType } from '@overflow/commons/core/type';
|
||||
import MemberReducer from '@overflow/modules/member/reducer/member_reducer';
|
||||
|
||||
|
||||
const reducers: ConstructorType[] = [
|
||||
const reducers: ClassType[] = [
|
||||
MemberReducer,
|
||||
];
|
||||
|
||||
|
@ -12,7 +18,7 @@ const state: any = {
|
|||
|
||||
export interface ReduxConfig {
|
||||
state: any;
|
||||
reducers: ConstructorType[];
|
||||
reducers: ClassType[];
|
||||
}
|
||||
|
||||
const reduxConfig: ReduxConfig = {
|
||||
|
|
22
src/ts/@overflow/webapp/config/injectables.ts
Normal file
22
src/ts/@overflow/webapp/config/injectables.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { InjectablesType } from '@overflow/commons/application/decorators';
|
||||
import { WebAppDispatcherReducer } from '../redux';
|
||||
|
||||
|
||||
export const injectables: InjectablesType = [
|
||||
WebAppDispatcherReducer,
|
||||
{
|
||||
injectType: WebAppDispatcherReducer,
|
||||
injectableType: WebAppDispatcherReducer,
|
||||
},
|
||||
{
|
||||
injectType: WebAppDispatcherReducer,
|
||||
injectableFactory: function(): any {
|
||||
return new WebAppDispatcherReducer();
|
||||
},
|
||||
},
|
||||
{
|
||||
injectName: 'Name',
|
||||
injectableValue: 'TestValue',
|
||||
},
|
||||
|
||||
];
|
21
src/ts/@overflow/webapp/config/reducer_configuration.ts
Normal file
21
src/ts/@overflow/webapp/config/reducer_configuration.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import {
|
||||
Store,
|
||||
} from 'redux';
|
||||
|
||||
import {
|
||||
Configuration,
|
||||
} from '@overflow/commons/application/decorators';
|
||||
|
||||
import {
|
||||
Injectable,
|
||||
} from '@overflow/commons/di/decorators';
|
||||
|
||||
|
||||
@Configuration()
|
||||
export class ReducerConfiguration {
|
||||
|
||||
@Injectable()
|
||||
public store(): Store<any> {
|
||||
return null;
|
||||
}
|
||||
}
|
7
src/ts/@overflow/webapp/config/rest_api_configuration.ts
Normal file
7
src/ts/@overflow/webapp/config/rest_api_configuration.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { Configuration } from '@overflow/commons/application/decorators';
|
||||
|
||||
|
||||
@Configuration()
|
||||
export class RestAPIConfiguration {
|
||||
|
||||
}
|
7
src/ts/@overflow/webapp/config/rpc_api_configuration.ts
Normal file
7
src/ts/@overflow/webapp/config/rpc_api_configuration.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { Configuration } from '@overflow/commons/application/decorators';
|
||||
|
||||
|
||||
@Configuration()
|
||||
export class RpcAPIConfiguration {
|
||||
|
||||
}
|
7
src/ts/@overflow/webapp/config/webapp_configuration.ts
Normal file
7
src/ts/@overflow/webapp/config/webapp_configuration.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { Configuration } from '@overflow/commons/application/decorators';
|
||||
|
||||
|
||||
@Configuration()
|
||||
export class WebAppConfiguration {
|
||||
|
||||
}
|
|
@ -28,11 +28,18 @@ import {
|
|||
AppContainer,
|
||||
} from 'react-hot-loader';
|
||||
|
||||
import { Application } from '@overflow/commons/application';
|
||||
import { WebApplication } from '@overflow/commons/application/decorators';
|
||||
import { Inject } from '@overflow/commons/di/decorators';
|
||||
|
||||
import config from './config';
|
||||
import WebAppDispatchReducer from './redux/webapp_dispatch_reducer';
|
||||
import config, {
|
||||
injectables,
|
||||
ReducerConfiguration,
|
||||
RestAPIConfiguration,
|
||||
RpcAPIConfiguration,
|
||||
WebAppConfiguration,
|
||||
} from './config';
|
||||
import {WebAppDispatcherReducer} from './redux';
|
||||
import WebApp from './pages/webapp';
|
||||
|
||||
// declare let module: { hot: any };
|
||||
|
@ -46,11 +53,12 @@ declare global {
|
|||
}
|
||||
|
||||
@WebApplication({
|
||||
injectables: [
|
||||
WebAppDispatchReducer,
|
||||
],
|
||||
injectables: injectables,
|
||||
configurations: [
|
||||
|
||||
ReducerConfiguration,
|
||||
RestAPIConfiguration,
|
||||
RpcAPIConfiguration,
|
||||
WebAppConfiguration,
|
||||
],
|
||||
})
|
||||
class WebAppApplication {
|
||||
|
@ -62,7 +70,7 @@ class WebAppApplication {
|
|||
private history: History;
|
||||
|
||||
@Inject()
|
||||
private dispatchReducer: WebAppDispatchReducer;
|
||||
private dispatcherReducer: WebAppDispatcherReducer;
|
||||
|
||||
public constructor() {
|
||||
this.container = document.getElementById('appContainer');
|
||||
|
@ -72,7 +80,7 @@ class WebAppApplication {
|
|||
public async run(): Promise<void> {
|
||||
try {
|
||||
this.renderLoading();
|
||||
let reducer: WebAppDispatchReducer = new WebAppDispatchReducer();
|
||||
let reducer: WebAppDispatcherReducer = new WebAppDispatcherReducer();
|
||||
reducer.registerReducers(config.redux.reducers);
|
||||
this.store = createStore(reducer.reducer, config.redux.state);
|
||||
|
||||
|
@ -179,4 +187,4 @@ class WebAppApplication {
|
|||
}
|
||||
}
|
||||
|
||||
WebAppApplication.main();
|
||||
Application.run(WebAppApplication);
|
||||
|
|
1
src/ts/@overflow/webapp/redux/index.ts
Normal file
1
src/ts/@overflow/webapp/redux/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './webapp_dispatch_reducer';
|
|
@ -2,10 +2,10 @@ import {
|
|||
Injectable,
|
||||
} from '@overflow/commons/di/decorators';
|
||||
|
||||
import DispatchReducer from '@overflow/commons/redux/dispatch_reducer';
|
||||
import {DispatcherReducer} from '@overflow/commons/redux';
|
||||
|
||||
@Injectable()
|
||||
export default class WebAppDispatchReducer extends DispatchReducer {
|
||||
export class WebAppDispatcherReducer extends DispatcherReducer {
|
||||
public constructor() {
|
||||
super();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user