# HG changeset patch # User ymh # Date 1497887803 -7200 # Node ID a2761c5be5513c8b973b30e8b393328d2253cca0 # Parent fad489be9c771cf509d3ca0bfbd44cb4c8365b0c put APIClient in context diff -r fad489be9c77 -r a2761c5be551 client/src/sagas/index.js --- a/client/src/sagas/index.js Mon Jun 19 17:30:03 2017 +0200 +++ b/client/src/sagas/index.js Mon Jun 19 17:56:43 2017 +0200 @@ -3,8 +3,6 @@ import * as types from '../constants/actionTypes'; import PouchDBFind from 'pouchdb-find'; import Immutable from 'immutable'; -import APIClient from '../APIClient'; -import config from '../config'; PouchDB.debug.disable(); PouchDB.plugin(PouchDBFind); @@ -15,8 +13,6 @@ index: { fields: ['session'] } }); -const client = new APIClient(config.apiRootUrl); - // --- export function* loadSessions() { @@ -99,11 +95,12 @@ } } -function* watchLoginRequest() { +function* watchLoginRequest(context) { while (true) { try { const { username, password } = yield take(types.AUTH_LOGIN_REQUEST); + const client = context['client']; const response = yield client.post('/api/auth/login/', { username, password }); localStorage.setItem('currentUser', JSON.stringify(response.user)); @@ -156,7 +153,7 @@ // --- -export default function* rootSaga() { +export default function* rootSaga(context) { yield all([ watchLoadSessions(), watchLoadNotesBySession(), @@ -164,7 +161,7 @@ watchCreateSession(), watchUpdateSession(), watchLoginSubmit(), - watchLoginRequest(), + watchLoginRequest(context), watchStoreToken(), watchUpdateSettings(), ]) diff -r fad489be9c77 -r a2761c5be551 client/src/store/configureStore.js --- a/client/src/store/configureStore.js Mon Jun 19 17:30:03 2017 +0200 +++ b/client/src/store/configureStore.js Mon Jun 19 17:56:43 2017 +0200 @@ -6,6 +6,8 @@ import handleTransitions from 'redux-history-transitions'; import createSagaMiddleware from 'redux-saga' import Immutable from 'immutable'; +import APIClient from '../APIClient'; +import config from '../config'; const token = localStorage.getItem('token'); const currentUser = localStorage.getItem('currentUser'); @@ -37,7 +39,11 @@ transitions )); - saga.run(rootSaga) + const context = { + client: new APIClient(config.apiRootUrl) + } + + saga.run(rootSaga, context); store.dispatch(loadSessions());