ing
This commit is contained in:
parent
2bc88e7a3d
commit
a115e94083
|
@ -4,12 +4,12 @@ import { call, fork, take } from 'redux-saga/effects';
|
||||||
|
|
||||||
import * as LifecycleActions from '../action/lifecycle';
|
import * as LifecycleActions from '../action/lifecycle';
|
||||||
|
|
||||||
import AppContext from '../../AppContext';
|
import AppContext from '../../';
|
||||||
|
|
||||||
|
|
||||||
function _destroy(): Promise<void> {
|
function _destroy(): Promise<void> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
AppContext.getInstance().destroy();
|
// AppContext.getInstance().destroy();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,10 @@ class InjectDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
private addValueProperty(value: string, propertyKey: string | symbol): void {
|
private addValueProperty(value: string, propertyKey: string | symbol): void {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
private addValueParameter(value: string, propertyKey: string | symbol, parameterIndex: number): void {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import {
|
||||||
|
Construtorable,
|
||||||
|
} from '@loafer/core/constants';
|
||||||
|
|
||||||
|
interface SingletonPouchRegistry {
|
||||||
|
registerSingleton(pouch: any, qualifier?: string | symbol): void;
|
||||||
|
getSingleton<T>(type: Construtorable<T>, qualifier?: string | symbol): T;
|
||||||
|
hasSingleton<T>(type: Construtorable<T>, qualifier?: string | symbol): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SingletonPouchRegistry;
|
|
@ -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<Object, Map<string | symbol, PouchDefinition>>;
|
||||||
|
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;
|
|
@ -1,5 +1,3 @@
|
||||||
import * as METADATA from '@loafer/pouches/constants';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Construtorable,
|
Construtorable,
|
||||||
DecoratorType,
|
DecoratorType,
|
||||||
|
@ -11,11 +9,13 @@ import {
|
||||||
} from '@loafer/pouches/constants';
|
} from '@loafer/pouches/constants';
|
||||||
|
|
||||||
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
|
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
|
||||||
|
import AbstractPouchFactory from '@loafer/pouches/factory/implement/AbstractPouchFactory';
|
||||||
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
|
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
|
||||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||||
|
|
||||||
class DefaultPouchFactory implements PouchFactory, PouchDefinitionRegistry {
|
class DefaultPouchFactory extends AbstractPouchFactory implements PouchFactory, PouchDefinitionRegistry {
|
||||||
public constructor() {
|
public constructor() {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPouch<T>(type: Construtorable<T>, ...args: any[]): T {
|
public getPouch<T>(type: Construtorable<T>, ...args: any[]): T {
|
||||||
|
@ -29,26 +29,6 @@ class DefaultPouchFactory implements PouchFactory, PouchDefinitionRegistry {
|
||||||
return instance;
|
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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<Object, Map<string | symbol, any>>;
|
||||||
|
|
||||||
|
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<T>(type: Construtorable<T>, qualifier?: string | symbol): T {
|
||||||
|
if (!this.singletonInstanceMap.has(type)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const _qualifier = validateQualifier(qualifier);
|
||||||
|
return this.singletonInstanceMap.get(type).get(qualifier);
|
||||||
|
}
|
||||||
|
public hasSingleton<T>(type: Construtorable<T>, qualifier?: string | symbol): boolean {
|
||||||
|
return undefined === this.getSingleton(type, qualifier) ? false : true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DefaultSingletonPouchRegistry;
|
|
@ -6,8 +6,6 @@ interface PouchDefinitionRegistry {
|
||||||
removePouchDefinition(type: Object, qualifier?: string | symbol): void;
|
removePouchDefinition(type: Object, qualifier?: string | symbol): void;
|
||||||
getPouchDefinition(type: Object, qualifier?: string | symbol): PouchDefinition;
|
getPouchDefinition(type: Object, qualifier?: string | symbol): PouchDefinition;
|
||||||
hasPouchDefinition(type: Object, qualifier?: string | symbol): boolean;
|
hasPouchDefinition(type: Object, qualifier?: string | symbol): boolean;
|
||||||
getPouchDefinitions(): PouchDefinition[];
|
|
||||||
getPouchDefinitionCount(): number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PouchDefinitionRegistry;
|
export default PouchDefinitionRegistry;
|
||||||
|
|
7
src/ts/@loafer/pouches/util/qualifier.ts
Normal file
7
src/ts/@loafer/pouches/util/qualifier.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import {
|
||||||
|
DEFAULT_QUALIFIER,
|
||||||
|
} from '@loafer/pouches/constants';
|
||||||
|
|
||||||
|
export const validateQualifier = (qualifier: string | symbol) => {
|
||||||
|
return undefined === qualifier ? DEFAULT_QUALIFIER : qualifier;
|
||||||
|
};
|
|
@ -3,7 +3,7 @@ import Pouch from '@loafer/context/decorator/Pouch';
|
||||||
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration()
|
||||||
class AppConfig {
|
class AppConfig {
|
||||||
/**
|
/**
|
||||||
* setWebsocket
|
* setWebsocket
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { ReducersMapObject } from 'redux';
|
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 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
|
// Container Configuration
|
||||||
export interface ContainerConfig {
|
export interface ContainerConfig {
|
||||||
|
@ -39,7 +39,6 @@ const reduxConfig: ReduxConfig = {
|
||||||
signInReducer,
|
signInReducer,
|
||||||
],
|
],
|
||||||
sagaWarchers: [
|
sagaWarchers: [
|
||||||
...signInSagaWatchers,
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,12 @@ import * as injectTapEventPlugin from 'react-tap-event-plugin';
|
||||||
|
|
||||||
import Platform from '@overflow/commons/platform';
|
import Platform from '@overflow/commons/platform';
|
||||||
import AppContext from '@loafer/context/AppContext';
|
import AppContext from '@loafer/context/AppContext';
|
||||||
|
import GetAppContext from '@loafer/context';
|
||||||
|
|
||||||
import * as AppContextLifecycleActions from '@loafer/context/redux/action/lifecycle';
|
import * as AppContextLifecycleActions from '@loafer/context/redux/action/lifecycle';
|
||||||
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
||||||
import ReducerContext from '@overflow/commons/redux/ReducerContext';
|
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';
|
import appConfig, { Config, ReduxState } from './config';
|
||||||
|
|
||||||
|
@ -92,7 +94,7 @@ class Application {
|
||||||
|
|
||||||
this.context = await this.initContext();
|
this.context = await this.initContext();
|
||||||
this.rpcClient = await this.initRpcClient();
|
this.rpcClient = await this.initRpcClient();
|
||||||
this.context.PouchFactory.registerPouch(this.rpcClient);
|
// this.context.PouchFactory.registerPouch(this.rpcClient);
|
||||||
|
|
||||||
await this.initRedux();
|
await this.initRedux();
|
||||||
|
|
||||||
|
@ -107,7 +109,7 @@ class Application {
|
||||||
|
|
||||||
private initContext(): Promise<AppContext> {
|
private initContext(): Promise<AppContext> {
|
||||||
const appContext = new Promise<AppContext>(resolve => {
|
const appContext = new Promise<AppContext>(resolve => {
|
||||||
const context = AppContext.getInstance();
|
const context = GetAppContext();
|
||||||
resolve(context);
|
resolve(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
1
src/ts/@overflow/commons/constant/index.ts
Normal file
1
src/ts/@overflow/commons/constant/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * from './types';
|
3
src/ts/@overflow/commons/constant/types.ts
Normal file
3
src/ts/@overflow/commons/constant/types.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import { SagaIterator } from 'redux-saga';
|
||||||
|
|
||||||
|
export type SagaWatcher = () => SagaIterator;
|
|
@ -1,7 +1,9 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
import { SagaIterator } from 'redux-saga';
|
||||||
import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects';
|
import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects';
|
||||||
|
|
||||||
|
import GetAppContext from '@loafer/context';
|
||||||
import AppContext from '@loafer/context/AppContext';
|
import AppContext from '@loafer/context/AppContext';
|
||||||
|
import { SagaWatcher } from '@overflow/commons/constant';
|
||||||
import Action from '@overflow/commons/redux/Action';
|
import Action from '@overflow/commons/redux/Action';
|
||||||
|
|
||||||
import * as AsyncRequestActions from '../action/asyncRequest';
|
import * as AsyncRequestActions from '../action/asyncRequest';
|
||||||
|
@ -14,17 +16,15 @@ function* request(action: Action<AsyncRequestPayload>): SagaIterator {
|
||||||
// type: types.SENDING_REQUEST,
|
// type: types.SENDING_REQUEST,
|
||||||
// payload: {sendingRequest: true},
|
// payload: {sendingRequest: true},
|
||||||
// });
|
// });
|
||||||
let serviceInstance = AppContext.getInstance().getService(service);
|
// let serviceInstance = GetAppContext().getPouch(service);
|
||||||
|
// const member = yield call({context: memberService, fn: memberService.signin}, signinId, signinPw);
|
||||||
|
|
||||||
const member = yield call({context: memberService, fn: memberService.signin}, signinId, signinPw);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
// if (responseBody.token === undefined) {
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
||||||
// }
|
// }
|
||||||
yield put(SigninActions.requestSuccess(member));
|
// yield put(SigninActions.requestSuccess(member));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yield put(SigninActions.requestFailure(e));
|
// yield put(SigninActions.requestFailure(e));
|
||||||
} finally {
|
} finally {
|
||||||
// yield put({
|
// yield put({
|
||||||
// type: types.SENDING_REQUEST,
|
// type: types.SENDING_REQUEST,
|
||||||
|
@ -37,6 +37,6 @@ function* watchAsyncRequest(): SagaIterator {
|
||||||
yield takeEvery(AsyncRequestActions.REQUEST, request);
|
yield takeEvery(AsyncRequestActions.REQUEST, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sagaWatchers: SagaWatcher[] = [watchSignin];
|
const sagaWatchers: SagaWatcher[] = [watchAsyncRequest];
|
||||||
|
|
||||||
export default sagaWatchers;
|
export default sagaWatchers;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
RPCResponse,
|
RPCResponse,
|
||||||
} from './protocol/rpc';
|
} 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 OnDisconnectFunc = () => void;
|
||||||
export type OnResponseFunc = (response: any) => void;
|
export type OnResponseFunc = (response: any) => void;
|
||||||
|
@ -36,7 +36,7 @@ enum WebSocketReadyState {
|
||||||
CLOSED = 3,
|
CLOSED = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable
|
@Injectable()
|
||||||
export default class WebSocketRPC {
|
export default class WebSocketRPC {
|
||||||
private url: string;
|
private url: string;
|
||||||
private connStatus: WebSocketStatus;
|
private connStatus: WebSocketStatus;
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import Service from '@overflow/commons/api/Service';
|
import Service from '@overflow/commons/api/Service';
|
||||||
import Member from '../model/Member';
|
import Member from '../model/Member';
|
||||||
import Injectable from '@overflow/commons/context/pouches/decorator/Injectable';
|
import Injectable from '@loafer/context/decorator/Injectable';
|
||||||
import inject from '@overflow/commons/context/pouches/decorator/Injectable';
|
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
@Injectable
|
|
||||||
export class MemberService extends Service {
|
export class MemberService extends Service {
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function mapStateToProps(state: any, ownProps?: any): SignInStateProps {
|
||||||
export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): SigninDispatchProps {
|
export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): SigninDispatchProps {
|
||||||
return {
|
return {
|
||||||
onSignIn: (signinId: string, signinPw: string) => {
|
onSignIn: (signinId: string, signinPw: string) => {
|
||||||
dispatch(signinActions.request(signinId, signinPw));
|
// dispatch(signinActions.request(signinId, signinPw));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user