ing
This commit is contained in:
parent
05f949fd3a
commit
d2c6a7b3b7
|
@ -108,14 +108,14 @@ class OFApplication {
|
|||
private initRpcClient(): Promise<WebSocketRPC> {
|
||||
const rpcClient = new Promise<WebSocketRPC>((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<SagaWatcher>[]): SagaIterator {
|
||||
for (let Watcher of sagaWarchers) {
|
||||
let instance = new Watcher();
|
||||
private * initReduxSagaWarchers(sagaWarchers: Class<SagaWatcher>[], 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});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<AsyncRequestPayload>): SagaIterator {
|
||||
public setWebSocketRPC(webSocketRPC: WebSocketRPC): void {
|
||||
this._webSocketRPC = webSocketRPC;
|
||||
}
|
||||
|
||||
private * request(webSocketRPC: WebSocketRPC, action: Action<AsyncRequestPayload>): 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<any>, ownProps?: any): Sig
|
|||
return {
|
||||
onSignIn: (signinId: string, signinPw: string) => {
|
||||
// dispatch(signinActions.request(signinId, signinPw));
|
||||
dispatch(asyncRequestActions.request('MemberService', 'signin', signinActions.REQUEST, signinId, signinPw));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user