This commit is contained in:
crusader 2017-08-01 01:20:21 +09:00
parent 2bc88e7a3d
commit a115e94083
17 changed files with 149 additions and 49 deletions

View File

@ -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<void> {
return new Promise(resolve => {
AppContext.getInstance().destroy();
// AppContext.getInstance().destroy();
resolve();
});
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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<T>(type: Construtorable<T>, ...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 {
}
}

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,7 @@
import {
DEFAULT_QUALIFIER,
} from '@loafer/pouches/constants';
export const validateQualifier = (qualifier: string | symbol) => {
return undefined === qualifier ? DEFAULT_QUALIFIER : qualifier;
};

View File

@ -3,7 +3,7 @@ import Pouch from '@loafer/context/decorator/Pouch';
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
@Configuration
@Configuration()
class AppConfig {
/**
* setWebsocket

View File

@ -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,
],
};

View File

@ -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<AppContext> {
const appContext = new Promise<AppContext>(resolve => {
const context = AppContext.getInstance();
const context = GetAppContext();
resolve(context);
});

View File

@ -0,0 +1 @@
export * from './types';

View File

@ -0,0 +1,3 @@
import { SagaIterator } from 'redux-saga';
export type SagaWatcher = () => SagaIterator;

View File

@ -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<AsyncRequestPayload>): 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;

View File

@ -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;

View File

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

View File

@ -18,7 +18,7 @@ export function mapStateToProps(state: any, ownProps?: any): SignInStateProps {
export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): SigninDispatchProps {
return {
onSignIn: (signinId: string, signinPw: string) => {
dispatch(signinActions.request(signinId, signinPw));
// dispatch(signinActions.request(signinId, signinPw));
},
};
}