diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts
index 1a72e80..6c3a492 100644
--- a/src/ts/@overflow/app/config/index.ts
+++ b/src/ts/@overflow/app/config/index.ts
@@ -1,5 +1,8 @@
import { ReducersMapObject } from 'redux';
+import { SagaWatcher } from '@overflow/commons/redux-saga';
+
import signInReducer from '@overflow/member/redux/reducer/signIn';
+import signInSagaWatchers from '@overflow/member/redux/saga/signIn';
// Container Configuration
export interface ContainerConfig {
@@ -21,17 +24,23 @@ const rpcConfig: RPCConfig = {
export interface ReduxConfig {
state: ReduxState;
reducerMaps: ReducersMapObject[];
+ sagaWarchers: (SagaWatcher[])[];
}
export interface ReduxState {
}
const reduxState: ReduxState = {};
+
+
const reduxConfig: ReduxConfig = {
state: reduxState,
reducerMaps: [
signInReducer,
],
+ sagaWarchers: [
+ signInSagaWatchers,
+ ],
};
diff --git a/src/ts/@overflow/app/index.tsx b/src/ts/@overflow/app/index.tsx
index 94b9c70..fbaa983 100644
--- a/src/ts/@overflow/app/index.tsx
+++ b/src/ts/@overflow/app/index.tsx
@@ -20,8 +20,15 @@ import {
import createSagaMiddleware, {
SagaMiddleware,
+ SagaIterator,
} from 'redux-saga';
+import {
+ fork,
+} from 'redux-saga/effects';
+
+
+
import {
createHashHistory,
History,
@@ -39,12 +46,10 @@ import AppContext from '@overflow/commons/context';
import * as AppContextLifecycleActions from '@overflow/commons/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 appConfig, { Config, ReduxState } from './config';
-import sagas from './redux/saga';
-// import routes from './router';
-
import App from './views/App';
injectTapEventPlugin();
@@ -81,7 +86,8 @@ class Application {
this.displayLoading();
this.context = await this.initContext();
- // this.rpcClient = await this.initRpcClient();
+ this.rpcClient = await this.initRpcClient();
+ this.context.put(this.rpcClient);
await this.initRedux();
@@ -141,13 +147,21 @@ class Application {
Application.useReduxDevTools ? compose(middleware, window.devToolsExtension()) : middleware,
);
// saga
- this.sagaMiddleware.run(sagas);
+ this.sagaMiddleware.run(this.initReduxSagaWarchers, this.config.redux.sagaWarchers);
resolve();
});
return init;
}
+ private * initReduxSagaWarchers(sagaWarchers: (SagaWatcher[])[]): SagaIterator {
+ for (let sagaWarcher of sagaWarchers) {
+ for (let warcher of sagaWarcher) {
+ yield fork(warcher);
+ }
+ }
+ }
+
private displayLoading(): void {
ReactDOM.render(
{
- return new Promise
(resolve => {
- resolve('');
- });
+ protected send(methodName: string, ...params: any[]): Promise {
+ return this.webSocketRPC.Call(methodName, params)
+ .then(body => {
+ const o: T = JSON.parse(body);
+ return o;
+ })
+ .catch(e => {
+ throw e;
+ });
}
}
diff --git a/src/ts/@overflow/commons/context/constants.ts b/src/ts/@overflow/commons/context/constants.ts
index e3a77ba..da82ee6 100644
--- a/src/ts/@overflow/commons/context/constants.ts
+++ b/src/ts/@overflow/commons/context/constants.ts
@@ -5,4 +5,4 @@ export const PARAM_TYPES = 'overflow:paramtypes';
export const DESIGN_PARAM_TYPES = 'design:paramtypes';
// The type of the binding at design time
-export const INJECT_TAG = 'inject';
+export const INJECT_TAG = '__inject__';
diff --git a/src/ts/@overflow/commons/context/decorator/inject.ts b/src/ts/@overflow/commons/context/decorator/inject.ts
index 8c3da12..814e35c 100644
--- a/src/ts/@overflow/commons/context/decorator/inject.ts
+++ b/src/ts/@overflow/commons/context/decorator/inject.ts
@@ -5,13 +5,24 @@ export interface Config {
required?: boolean;
}
+
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);
+ if (Reflect.hasOwnMetadata(METADATA.INJECT_TAG, target)) {
+ let meta = Reflect.getMetadata(METADATA.INJECT_TAG, target);
+ } else {
+ let meta: string[];
+ }
+
+ let types = Reflect.getMetadata(METADATA.INJECT_TAG, target);
+
+ // Reflect.defineMetadata(METADATA.PARAM_TYPES, types, target);
+
+ console.log(types);
// tagProperty(target, targetKey, metadata);
}
};
diff --git a/src/ts/@overflow/commons/context/index.ts b/src/ts/@overflow/commons/context/index.ts
index fbaa4f8..3fa639c 100644
--- a/src/ts/@overflow/commons/context/index.ts
+++ b/src/ts/@overflow/commons/context/index.ts
@@ -1,12 +1,28 @@
+import * as METADATA from './constants';
+
class AppContext {
private static context: AppContext = null;
+ private instanceMap: Map;
private constructor() {
-
+ this.instanceMap = new Map();
}
- public static getService(): T {
- return null;
+ public put(instance: any, name?: string): void {
+ if (typeof name !== 'string') {
+ if (instance instanceof Function) {
+ name = (instance).name;
+ }
+ }
+ this.instanceMap.set(name, instance);
+ }
+
+ public static getService(clazz: {new(...args: any[]): T}): T {
+ let types = Reflect.getMetadata(METADATA.PARAM_TYPES, clazz);
+
+ let i = new clazz();
+
+ return i;
}
public static get(): T {
@@ -15,10 +31,8 @@ class AppContext {
return null;
}
- public static put(instance: T): void {
-
-
- return null;
+ public static put(instance: any, name?: string): void {
+ AppContext.getContext().put(instance, name);
}
public static getContext(): AppContext {
diff --git a/src/ts/@overflow/commons/redux-saga/index.ts b/src/ts/@overflow/commons/redux-saga/index.ts
new file mode 100644
index 0000000..bed9be2
--- /dev/null
+++ b/src/ts/@overflow/commons/redux-saga/index.ts
@@ -0,0 +1,3 @@
+import { SagaIterator } from 'redux-saga';
+
+export type SagaWatcher = () => SagaIterator;
diff --git a/src/ts/@overflow/commons/redux/ReducerContext.ts b/src/ts/@overflow/commons/redux/ReducerContext.ts
index f327577..dd441fe 100644
--- a/src/ts/@overflow/commons/redux/ReducerContext.ts
+++ b/src/ts/@overflow/commons/redux/ReducerContext.ts
@@ -6,7 +6,8 @@ interface ReducerItem {
}
class ReducerContext {
- private static instance: ReducerContext = new ReducerContext();
+ private static readonly instance: ReducerContext = new ReducerContext();
+ private static readonly sagaActionKey: string = '@@redux-saga/SAGA_ACTION';
private reducerMap: Map[]>;
private constructor() {
@@ -26,7 +27,9 @@ class ReducerContext {
}
public static reducer(state: State, action: A): State {
- const actionType = action.type;
+ const actionType: string = action.type;
+ const isSagaAction = action.hasOwnProperty(ReducerContext.sagaActionKey) ? action[ReducerContext.sagaActionKey] : false;
+
if (ReducerContext.getInstance().reducerMap.has(actionType)) {
let reducerItems = ReducerContext.getInstance().reducerMap.get(actionType);
for (let reducerItem of reducerItems) {
@@ -34,7 +37,9 @@ class ReducerContext {
state = reducer(state, action);
}
} else {
- console.log(`Reducer for [${actionType}] is not exist in the context.`);
+ if (-1 === actionType.indexOf('@@')) {
+ console.log(`Reducer for [${actionType}] is not exist in the context.`);
+ }
}
return state;
}
diff --git a/src/ts/@overflow/commons/redux/StateTreeManager.ts b/src/ts/@overflow/commons/redux/StateTreeManager.ts
deleted file mode 100644
index e69de29..0000000
diff --git a/src/ts/@overflow/commons/redux/createReducer.ts b/src/ts/@overflow/commons/redux/createReducer.ts
deleted file mode 100644
index 1058e05..0000000
--- a/src/ts/@overflow/commons/redux/createReducer.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import Action from './Action';
-import * as Redux from 'redux';
-
-// export type Reducer = (state: S, action: A) => S;
-
-// export interface ReducersMapObject {
-// [key: string]: Reducer;
-// }
-
-const createReducer = (initialState: State, handlers: Redux.ReducersMapObject): Redux.Reducer => {
- return (state: State = initialState, action: A): State => {
- if (handlers[action.type]) {
- return handlers[action.type](state, action);
- }
- return state;
- };
-};
-
-export default createReducer;
diff --git a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts
index db1836c..c13ebe4 100644
--- a/src/ts/@overflow/commons/websocket/WebSocketRPC.ts
+++ b/src/ts/@overflow/commons/websocket/WebSocketRPC.ts
@@ -58,10 +58,8 @@ export default class WebSocketRPC {
this.requestQueue = new Map();
}
- public Call(method: string, params: any[]): Promise {
-
-
- return new Promise((resolve, reject) => {
+ public Call(method: string, params: any[]): Promise {
+ return new Promise((resolve, reject) => {
const requestID = this.getRequestID();
let request = new ProtocolRequest(RPCProtocol, requestID);
let req = new RPCRequest(method, params);
diff --git a/src/ts/@overflow/member/api/service/MemberService.ts b/src/ts/@overflow/member/api/service/MemberService.ts
index fd03e76..b460da0 100644
--- a/src/ts/@overflow/member/api/service/MemberService.ts
+++ b/src/ts/@overflow/member/api/service/MemberService.ts
@@ -12,12 +12,7 @@ export class MemberService extends Service {
}
public signin(signinId: string, signinPw: string): Promise {
- return new Promise(resolve => {
- const json = this.send('signin', [signinId, signinPw]);
- let member: Member;
- // member = ........(json);
- resolve(member);
- });
+ return this.send('signin', [signinId, signinPw]);
}
public signout(member: Member): Member {
diff --git a/src/ts/@overflow/member/react/SignIn.tsx b/src/ts/@overflow/member/react/SignIn.tsx
index b8a100c..4f5dfe2 100644
--- a/src/ts/@overflow/member/react/SignIn.tsx
+++ b/src/ts/@overflow/member/react/SignIn.tsx
@@ -9,13 +9,13 @@ import State from '../redux/state/SignIn';
import * as signinActions from '../redux/action/signIn';
-export function mapStateToProps(state: any): SignInStateProps {
+export function mapStateToProps(state: any, ownProps?: any): SignInStateProps {
return {
};
}
-export function mapDispatchToProps(dispatch: Dispatch): SigninDispatchProps {
+export function mapDispatchToProps(dispatch: Dispatch, ownProps?: any): SigninDispatchProps {
return {
onSignIn: (signinId: string, signinPw: string) => {
dispatch(signinActions.request(signinId, signinPw));
diff --git a/src/ts/@overflow/member/redux/saga/signIn.ts b/src/ts/@overflow/member/redux/saga/signIn.ts
index 1befd07..b1fa1c2 100644
--- a/src/ts/@overflow/member/redux/saga/signIn.ts
+++ b/src/ts/@overflow/member/redux/saga/signIn.ts
@@ -1,6 +1,7 @@
import { SagaIterator } from 'redux-saga';
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
+import { SagaWatcher } from '@overflow/commons/redux-saga';
import AppContext from '@overflow/commons/context';
import Action from '@overflow/commons/redux/Action';
@@ -18,7 +19,7 @@ function* signin(action: Action): SagaIterator {
// payload: {sendingRequest: true},
// });
- const member = yield call(AppContext.getService().signin, signinId, signinPw);
+ const member = yield call(AppContext.getService(MemberService).signin, signinId, signinPw);
// if (responseBody.token === undefined) {
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
@@ -34,6 +35,10 @@ function* signin(action: Action): SagaIterator {
}
}
-export function* watchSignin(): SagaIterator {
+function* watchSignin(): SagaIterator {
yield takeLatest(SigninActions.REQUEST, signin);
}
+
+const sagaWatchers: SagaWatcher[] = [watchSignin];
+
+export default sagaWatchers;