vn-verdnaturachat/app/sagas/connect.js

28 lines
770 B
JavaScript
Raw Normal View History

import { put, call, takeLatest, select } from 'redux-saga/effects';
2017-08-17 01:06:31 +00:00
import { METEOR } from '../actions/actionsTypes';
import RocketChat from '../lib/rocketchat';
import { connectSuccess, connectFailure } from '../actions/connect';
2017-08-17 01:06:31 +00:00
const getServer = ({ server }) => server.server;
const connect = url => RocketChat.connect(url);
2017-08-17 16:55:47 +00:00
const test = function* test() {
try {
const server = yield select(getServer);
const response = yield call(connect, server);
yield put(connectSuccess(response));
} catch (err) {
yield put(connectFailure(err.status));
}
2017-08-17 16:55:47 +00:00
};
// const watchConnect = function* watchConnect() {
// };
2017-08-17 16:55:47 +00:00
const root = function* root() {
yield takeLatest(METEOR.REQUEST, test);
// yield fork(watchConnect);
2017-08-17 16:55:47 +00:00
// yield fork(auto);
};
export default root;