Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
Fix double call to demos sagas
Browse files Browse the repository at this point in the history
  • Loading branch information
rvennam committed Jan 27, 2017
2 parents cb101b6 + 69444ab commit 226cbd4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/modules/demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ export function *watchEndDemoSession() {
yield take(END_DEMO_SESSION);
const demoState = yield select(demoSelector);
try {
yield call(api.endDemo, demoState.guid, demoState.token);
yield call(api.endDemo, demoState.guid);
}
catch (error) {
console.log('ERROR DURING LOGOUT: probably because we are calling logout twice. BUG');
console.log('Error during logout', error);
}
window.localStorage.removeItem('savedGuid');
yield put(push('/'));
Expand Down
10 changes: 7 additions & 3 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export const callApi = (endpoint, {
method,
body: JSON.stringify(body),
})
.then(response => response.json().then(json => ({ json, response })))
.then(response => {
if (response.status === 204) { // good response but no content
return { json: { status: 204, statusText: 'no content' }, response };
}
return response.json().then(json => ({ json, response }));
})
.then(({ json, response }) => {
if (!response.ok) {
console.log(`Error calling URL : ${apiUrl}`);
Expand All @@ -28,9 +33,8 @@ export const createDemo = () =>

export const getDemo = guid => callApi(`demos/${guid}`);

export const endDemo = (guid, token) =>
export const endDemo = (guid) =>
callApi(`demos/${guid}`, {
headers: { Authorization: `Bearer ${token}` },
method: 'DELETE',
});

Expand Down
6 changes: 5 additions & 1 deletion src/store/createStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { applyMiddleware, compose, createStore } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import createSagaMiddleware from 'redux-saga';
import { sagas as demosSagas } from 'modules/demos';
import makeRootReducer from './reducers';
import makeRootSaga from './sagas';
import { makeRootSaga, injectSagas } from './sagas';

export default (initialState = {}, history) => {
// ======================================================
Expand Down Expand Up @@ -40,6 +41,9 @@ export default (initialState = {}, history) => {
};
store.runSaga(makeRootSaga(store.asyncSagas));

// inject the base sagas to login/logout of a demo session
injectSagas(store, { key: 'demos', sagas: demosSagas });

if (module.hot) {
module.hot.accept('./reducers', () => {
const reducers = require('./reducers').default;
Expand Down
3 changes: 0 additions & 3 deletions src/store/sagas.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { fork } from 'redux-saga/effects';

const demosSagas = require('modules/demos').sagas;

export const makeRootSaga = asyncSagas => function *rootSaga() {
yield [
...demosSagas,
...asyncSagas,
].map(saga => fork(saga));
};
Expand Down

0 comments on commit 226cbd4

Please sign in to comment.