diff --git a/src/ts/@overflow/app/index.tsx b/src/ts/@overflow/app/index.tsx index 4146ffc..627883b 100644 --- a/src/ts/@overflow/app/index.tsx +++ b/src/ts/@overflow/app/index.tsx @@ -108,14 +108,14 @@ class OFApplication { private initRpcClient(): Promise { const rpcClient = new Promise((resolve, reject) => { let client = new WebSocketRPC(this.config.rpc.url); - // client.initialize() - // .then(() => { - // resolve(client); - // }) - // .catch((err: any) => { - // reject(err); - // }); - resolve(client); + client.initialize() + .then(() => { + resolve(client); + }) + .catch((err: any) => { + reject(err); + }); + // resolve(client); }); return rpcClient; @@ -144,16 +144,21 @@ class OFApplication { OFApplication.useReduxDevTools ? compose(middleware, window.devToolsExtension()) : middleware, ); // saga - this.sagaMiddleware.run(this.initReduxSagaWarchers, this.config.redux.sagaWarchers); + this.sagaMiddleware.run(this.initReduxSagaWarchers, this.config.redux.sagaWarchers, this.rpcClient); resolve(); }); return init; } - private * initReduxSagaWarchers(sagaWarchers: Class[]): SagaIterator { - for (let Watcher of sagaWarchers) { - let instance = new Watcher(); + private * initReduxSagaWarchers(sagaWarchers: Class[], rpcClient: WebSocketRPC): SagaIterator { + for (let type of sagaWarchers) { + + let instance = Object.create(type.prototype); + instance.constructor.call(instance); + if (type.prototype.hasOwnProperty('setWebSocketRPC')) { + instance.setWebSocketRPC.call(instance, rpcClient); + } yield fork({context: instance, fn: instance.watch}); } } diff --git a/src/ts/@overflow/app/redux/saga/AsyncRequest.ts b/src/ts/@overflow/app/redux/saga/AsyncRequest.ts index 1fe4511..00414ae 100644 --- a/src/ts/@overflow/app/redux/saga/AsyncRequest.ts +++ b/src/ts/@overflow/app/redux/saga/AsyncRequest.ts @@ -11,17 +11,21 @@ import SagaWatcher from '@overflow/commons/redux/saga/SagaWatcher'; export class AsyncRequest implements SagaWatcher { - private webSocketRPC: WebSocketRPC; + private _webSocketRPC: WebSocketRPC; - private * request(action: Action): SagaIterator { + public setWebSocketRPC(webSocketRPC: WebSocketRPC): void { + this._webSocketRPC = webSocketRPC; + } + + private * request(webSocketRPC: WebSocketRPC, action: Action): SagaIterator { const {service, method, requestType, args} = action.payload; try { // yield put({ // type: types.SENDING_REQUEST, // payload: {sendingRequest: true}, // });`${service}.${method}` - // let webSocketRPC: WebSocketRPC = GetAppContext().getPouchByClass(WebSocketRPC.prototype, undefined); - let result = yield call({context: this.webSocketRPC, fn: this.webSocketRPC.Call}, `${service}.${method}`, args); + + let result = yield call({context: webSocketRPC, fn: webSocketRPC.Call}, `${service}.${method}`, args); // yield put(AsyncRequestActions.requestSuccess(requestType, result)); } catch (e) { @@ -35,7 +39,7 @@ export class AsyncRequest implements SagaWatcher { } public * watch(): SagaIterator { - yield takeEvery(AsyncRequestActions.REQUEST, this.request); + yield takeEvery(AsyncRequestActions.REQUEST, this.request, this._webSocketRPC); } } diff --git a/src/ts/@overflow/member/react/SignIn.tsx b/src/ts/@overflow/member/react/SignIn.tsx index 024aa35..74ce8d7 100644 --- a/src/ts/@overflow/member/react/SignIn.tsx +++ b/src/ts/@overflow/member/react/SignIn.tsx @@ -8,6 +8,7 @@ import State from '../redux/state/SignIn'; import * as signinActions from '../redux/action/signIn'; +import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; export function mapStateToProps(state: any, ownProps?: any): SignInStateProps { return { @@ -19,6 +20,7 @@ export function mapDispatchToProps(dispatch: Dispatch, ownProps?: any): Sig return { onSignIn: (signinId: string, signinPw: string) => { // dispatch(signinActions.request(signinId, signinPw)); + dispatch(asyncRequestActions.request('MemberService', 'signin', signinActions.REQUEST, signinId, signinPw)); }, }; }