diff --git a/src/ts/@loafer/context/redux/saga/index.ts b/src/ts/@loafer/context/redux/saga/index.ts index 913c730..0aff5a4 100644 --- a/src/ts/@loafer/context/redux/saga/index.ts +++ b/src/ts/@loafer/context/redux/saga/index.ts @@ -4,12 +4,12 @@ import { call, fork, take } from 'redux-saga/effects'; import * as LifecycleActions from '../action/lifecycle'; -import AppContext from '../../AppContext'; +import AppContext from '../../'; function _destroy(): Promise { return new Promise(resolve => { - AppContext.getInstance().destroy(); + // AppContext.getInstance().destroy(); resolve(); }); } diff --git a/src/ts/@loafer/pouches/definition/InjectDefinition.ts b/src/ts/@loafer/pouches/definition/InjectDefinition.ts index 9e0e8db..3fef19c 100644 --- a/src/ts/@loafer/pouches/definition/InjectDefinition.ts +++ b/src/ts/@loafer/pouches/definition/InjectDefinition.ts @@ -53,7 +53,10 @@ class InjectDefinition { } private addValueProperty(value: string, propertyKey: string | symbol): void { - + return; + } + private addValueParameter(value: string, propertyKey: string | symbol, parameterIndex: number): void { + return; } diff --git a/src/ts/@loafer/pouches/factory/config/SingletonPouchRegistry.ts b/src/ts/@loafer/pouches/factory/config/SingletonPouchRegistry.ts new file mode 100644 index 0000000..a6c9848 --- /dev/null +++ b/src/ts/@loafer/pouches/factory/config/SingletonPouchRegistry.ts @@ -0,0 +1,11 @@ +import { + Construtorable, +} from '@loafer/core/constants'; + +interface SingletonPouchRegistry { + registerSingleton(pouch: any, qualifier?: string | symbol): void; + getSingleton(type: Construtorable, qualifier?: string | symbol): T; + hasSingleton(type: Construtorable, qualifier?: string | symbol): boolean; +} + +export default SingletonPouchRegistry; diff --git a/src/ts/@loafer/pouches/factory/implement/AbstractPouchFactory.ts b/src/ts/@loafer/pouches/factory/implement/AbstractPouchFactory.ts new file mode 100644 index 0000000..136bd1d --- /dev/null +++ b/src/ts/@loafer/pouches/factory/implement/AbstractPouchFactory.ts @@ -0,0 +1,56 @@ +import { + validateQualifier, +} from '@loafer/pouches/util/qualifier'; + +import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; +import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry'; +import DefaultSingletonPouchRegistry from '@loafer/pouches/factory/implement/DefaultSingletonPouchRegistry'; + + + +abstract class AbstractPouchFactory extends DefaultSingletonPouchRegistry implements PouchDefinitionRegistry { + protected pouchDefinitionMap: Map>; + public constructor() { + super(); + this.pouchDefinitionMap = new Map(); + } + + public registerPouchDefinition(pouchDefinition: PouchDefinition): void { + let type = pouchDefinition.Type; + let qualifier = pouchDefinition.Qualifier; + + if (this.hasPouchDefinition(type, qualifier)) { + throw new Error(`Pouch Definition[${type.constructor.name}:${qualifier}] is exist already`); + } + let map = this.pouchDefinitionMap.get(type); + if (undefined === map) { + map = new Map(); + } + map.set(qualifier, pouchDefinition); + } + public removePouchDefinition(type: Object, qualifier?: string | symbol): void { + if (!this.hasPouchDefinition(type, qualifier)) { + throw new Error(`Pouch Definition[${type.constructor.name}:${qualifier}] is not exist`); + } + const _qualifier = validateQualifier(qualifier); + this.pouchDefinitionMap.get(type).delete(_qualifier); + if (0 === this.pouchDefinitionMap.get(type).size) { + this.pouchDefinitionMap.delete(type); + } + } + public getPouchDefinition(type: Object, qualifier?: string | symbol): PouchDefinition { + if (!this.pouchDefinitionMap.has(type)) { + return undefined; + } + const _qualifier = validateQualifier(qualifier); + return this.pouchDefinitionMap.get(type).get(qualifier); + } + public hasPouchDefinition(type: Object, qualifier?: string | symbol): boolean { + return undefined === this.getPouchDefinition(type, qualifier) ? false : true; + } + + + +} + +export default AbstractPouchFactory; diff --git a/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts b/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts index 0f6877c..fc33ef6 100644 --- a/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts +++ b/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts @@ -1,5 +1,3 @@ -import * as METADATA from '@loafer/pouches/constants'; - import { Construtorable, DecoratorType, @@ -11,11 +9,13 @@ import { } from '@loafer/pouches/constants'; import PouchFactory from '@loafer/pouches/factory/PouchFactory'; +import AbstractPouchFactory from '@loafer/pouches/factory/implement/AbstractPouchFactory'; import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry'; -class DefaultPouchFactory implements PouchFactory, PouchDefinitionRegistry { +class DefaultPouchFactory extends AbstractPouchFactory implements PouchFactory, PouchDefinitionRegistry { public constructor() { + super(); } public getPouch(type: Construtorable, ...args: any[]): T { @@ -29,26 +29,6 @@ class DefaultPouchFactory implements PouchFactory, PouchDefinitionRegistry { return instance; } - public registerPouchDefinition(pouchDefinition: PouchDefinition): void { - let type = pouchDefinition.Type; - let qualifier = pouchDefinition.Qualifier; - - } - public removePouchDefinition(type: Object, qualifier?: string | symbol): void { - - } - public getPouchDefinition(type: Object, qualifier?: string | symbol): PouchDefinition { - - } - public hasPouchDefinition(type: Object, qualifier?: string | symbol): boolean { - - } - public getPouchDefinitions(): PouchDefinition[] { - - } - public getPouchDefinitionCount(): number { - - } } diff --git a/src/ts/@loafer/pouches/factory/implement/DefaultSingletonPouchRegistry.ts b/src/ts/@loafer/pouches/factory/implement/DefaultSingletonPouchRegistry.ts new file mode 100644 index 0000000..1c48204 --- /dev/null +++ b/src/ts/@loafer/pouches/factory/implement/DefaultSingletonPouchRegistry.ts @@ -0,0 +1,42 @@ +import { + Construtorable, +} from '@loafer/core/constants'; + +import SingletonPouchRegistry from '@loafer/pouches/factory/config/SingletonPouchRegistry'; + +import { + validateQualifier, +} from '@loafer/pouches/util/qualifier'; + +class DefaultSingletonPouchRegistry implements SingletonPouchRegistry { + protected singletonInstanceMap: Map>; + + protected constructor() { + } + + public registerSingleton(pouch: any, qualifier?: string | symbol): void { + let type = Object.getPrototypeOf(pouch); + const _qualifier = validateQualifier(qualifier); + + if (this.hasSingleton(type, qualifier)) { + throw new Error(`Pouch Definition[${type.constructor.name}:${qualifier}] is exist already`); + } + let map = this.singletonInstanceMap.get(type); + if (undefined === map) { + map = new Map(); + } + map.set(qualifier, pouch); + } + public getSingleton(type: Construtorable, qualifier?: string | symbol): T { + if (!this.singletonInstanceMap.has(type)) { + return undefined; + } + const _qualifier = validateQualifier(qualifier); + return this.singletonInstanceMap.get(type).get(qualifier); + } + public hasSingleton(type: Construtorable, qualifier?: string | symbol): boolean { + return undefined === this.getSingleton(type, qualifier) ? false : true; + } +} + +export default DefaultSingletonPouchRegistry; diff --git a/src/ts/@loafer/pouches/factory/registry/PouchDefinitionRegistry.ts b/src/ts/@loafer/pouches/factory/registry/PouchDefinitionRegistry.ts index 19a6509..cd822d2 100644 --- a/src/ts/@loafer/pouches/factory/registry/PouchDefinitionRegistry.ts +++ b/src/ts/@loafer/pouches/factory/registry/PouchDefinitionRegistry.ts @@ -6,8 +6,6 @@ interface PouchDefinitionRegistry { removePouchDefinition(type: Object, qualifier?: string | symbol): void; getPouchDefinition(type: Object, qualifier?: string | symbol): PouchDefinition; hasPouchDefinition(type: Object, qualifier?: string | symbol): boolean; - getPouchDefinitions(): PouchDefinition[]; - getPouchDefinitionCount(): number; } export default PouchDefinitionRegistry; diff --git a/src/ts/@loafer/pouches/util/qualifier.ts b/src/ts/@loafer/pouches/util/qualifier.ts new file mode 100644 index 0000000..be54a85 --- /dev/null +++ b/src/ts/@loafer/pouches/util/qualifier.ts @@ -0,0 +1,7 @@ +import { + DEFAULT_QUALIFIER, +} from '@loafer/pouches/constants'; + +export const validateQualifier = (qualifier: string | symbol) => { + return undefined === qualifier ? DEFAULT_QUALIFIER : qualifier; +}; diff --git a/src/ts/@overflow/app/config/AppConfig.ts b/src/ts/@overflow/app/config/AppConfig.ts index 3d590a5..158a828 100644 --- a/src/ts/@overflow/app/config/AppConfig.ts +++ b/src/ts/@overflow/app/config/AppConfig.ts @@ -3,7 +3,7 @@ import Pouch from '@loafer/context/decorator/Pouch'; import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC'; -@Configuration +@Configuration() class AppConfig { /** * setWebsocket diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 7e46695..9c55950 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -1,8 +1,8 @@ import { ReducersMapObject } from 'redux'; -import { SagaWatcher } from '@overflow/commons/redux-saga'; +import { SagaWatcher } from '@overflow/commons/constant'; import signInReducer from '@overflow/member/redux/reducer/signIn'; -import signInSagaWatchers from '@overflow/member/redux/saga/signIn'; +// import signInSagaWatchers from '@overflow/member/redux/saga/signIn'; // Container Configuration export interface ContainerConfig { @@ -39,7 +39,6 @@ const reduxConfig: ReduxConfig = { signInReducer, ], sagaWarchers: [ - ...signInSagaWatchers, ], }; diff --git a/src/ts/@overflow/app/index.tsx b/src/ts/@overflow/app/index.tsx index 81f953b..6cc1441 100644 --- a/src/ts/@overflow/app/index.tsx +++ b/src/ts/@overflow/app/index.tsx @@ -43,10 +43,12 @@ import * as injectTapEventPlugin from 'react-tap-event-plugin'; import Platform from '@overflow/commons/platform'; import AppContext from '@loafer/context/AppContext'; +import GetAppContext from '@loafer/context'; + import * as AppContextLifecycleActions from '@loafer/context/redux/action/lifecycle'; import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC'; import ReducerContext from '@overflow/commons/redux/ReducerContext'; -import { SagaWatcher } from '@overflow/commons/redux-saga'; +import { SagaWatcher } from '@overflow/commons/constant'; import appConfig, { Config, ReduxState } from './config'; @@ -92,7 +94,7 @@ class Application { this.context = await this.initContext(); this.rpcClient = await this.initRpcClient(); - this.context.PouchFactory.registerPouch(this.rpcClient); + // this.context.PouchFactory.registerPouch(this.rpcClient); await this.initRedux(); @@ -107,7 +109,7 @@ class Application { private initContext(): Promise { const appContext = new Promise(resolve => { - const context = AppContext.getInstance(); + const context = GetAppContext(); resolve(context); }); diff --git a/src/ts/@overflow/commons/constant/index.ts b/src/ts/@overflow/commons/constant/index.ts new file mode 100644 index 0000000..fcb073f --- /dev/null +++ b/src/ts/@overflow/commons/constant/index.ts @@ -0,0 +1 @@ +export * from './types'; diff --git a/src/ts/@overflow/commons/constant/types.ts b/src/ts/@overflow/commons/constant/types.ts new file mode 100644 index 0000000..bed9be2 --- /dev/null +++ b/src/ts/@overflow/commons/constant/types.ts @@ -0,0 +1,3 @@ +import { SagaIterator } from 'redux-saga'; + +export type SagaWatcher = () => SagaIterator; diff --git a/src/ts/@overflow/commons/redux/saga/asyncRequest.ts b/src/ts/@overflow/commons/redux/saga/asyncRequest.ts index 244d352..1fe6adc 100644 --- a/src/ts/@overflow/commons/redux/saga/asyncRequest.ts +++ b/src/ts/@overflow/commons/redux/saga/asyncRequest.ts @@ -1,7 +1,9 @@ import { SagaIterator } from 'redux-saga'; import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects'; +import GetAppContext from '@loafer/context'; import AppContext from '@loafer/context/AppContext'; +import { SagaWatcher } from '@overflow/commons/constant'; import Action from '@overflow/commons/redux/Action'; import * as AsyncRequestActions from '../action/asyncRequest'; @@ -14,17 +16,15 @@ function* request(action: Action): SagaIterator { // type: types.SENDING_REQUEST, // payload: {sendingRequest: true}, // }); - let serviceInstance = AppContext.getInstance().getService(service); - - - const member = yield call({context: memberService, fn: memberService.signin}, signinId, signinPw); + // let serviceInstance = GetAppContext().getPouch(service); + // const member = yield call({context: memberService, fn: memberService.signin}, signinId, signinPw); // if (responseBody.token === undefined) { // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); // } - yield put(SigninActions.requestSuccess(member)); + // yield put(SigninActions.requestSuccess(member)); } catch (e) { - yield put(SigninActions.requestFailure(e)); + // yield put(SigninActions.requestFailure(e)); } finally { // yield put({ // type: types.SENDING_REQUEST, @@ -37,6 +37,6 @@ function* watchAsyncRequest(): SagaIterator { yield takeEvery(AsyncRequestActions.REQUEST, request); } -const sagaWatchers: SagaWatcher[] = [watchSignin]; +const sagaWatchers: SagaWatcher[] = [watchAsyncRequest]; export default sagaWatchers; diff --git a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts index 77196c7..56092bb 100644 --- a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts +++ b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts @@ -10,7 +10,7 @@ import { RPCResponse, } from './protocol/rpc'; -import Injectable from '@overflow/commons/context/pouches/decorator/Injectable'; +import Injectable from '@loafer/context/decorator/Injectable'; export type OnDisconnectFunc = () => void; export type OnResponseFunc = (response: any) => void; @@ -36,7 +36,7 @@ enum WebSocketReadyState { CLOSED = 3, } -@Injectable +@Injectable() export default class WebSocketRPC { private url: string; private connStatus: WebSocketStatus; diff --git a/src/ts/@overflow/member/api/service/MemberService.ts b/src/ts/@overflow/member/api/service/MemberService.ts index 25b351c..c3d57c7 100644 --- a/src/ts/@overflow/member/api/service/MemberService.ts +++ b/src/ts/@overflow/member/api/service/MemberService.ts @@ -1,11 +1,9 @@ import Service from '@overflow/commons/api/Service'; import Member from '../model/Member'; -import Injectable from '@overflow/commons/context/pouches/decorator/Injectable'; -import inject from '@overflow/commons/context/pouches/decorator/Injectable'; +import Injectable from '@loafer/context/decorator/Injectable'; - -@Injectable +@Injectable() export class MemberService extends Service { public constructor() { diff --git a/src/ts/@overflow/member/react/SignIn.tsx b/src/ts/@overflow/member/react/SignIn.tsx index 4f5dfe2..024aa35 100644 --- a/src/ts/@overflow/member/react/SignIn.tsx +++ b/src/ts/@overflow/member/react/SignIn.tsx @@ -18,7 +18,7 @@ export function mapStateToProps(state: any, ownProps?: any): SignInStateProps { export function mapDispatchToProps(dispatch: Dispatch, ownProps?: any): SigninDispatchProps { return { onSignIn: (signinId: string, signinPw: string) => { - dispatch(signinActions.request(signinId, signinPw)); + // dispatch(signinActions.request(signinId, signinPw)); }, }; }