Fix app sagas in charge of fetching models

This commit is contained in:
cyril lopez 2017-08-17 09:48:44 +02:00
parent e29cbfdab2
commit 6a7ca0c005
5 changed files with 8 additions and 4 deletions

View File

@ -7,12 +7,14 @@
import { MODELS_FETCH, MODELS_FETCH_SUCCEEDED } from './constants'; import { MODELS_FETCH, MODELS_FETCH_SUCCEEDED } from './constants';
export function modelsFetch() { export function modelsFetch() {
console.log('fetching models');
return { return {
type: MODELS_FETCH, type: MODELS_FETCH,
}; };
} }
export function modelsFetchSucceeded(models) { export function modelsFetchSucceeded(models) {
console.log('succeeded');
return { return {
type: MODELS_FETCH_SUCCEEDED, type: MODELS_FETCH_SUCCEEDED,
models, models,

View File

@ -24,6 +24,7 @@ define(map(messages, (message, id) => ({
class App extends React.Component { class App extends React.Component {
componentDidMount() { componentDidMount() {
console.log('did mount');
this.props.modelsFetch(); this.props.modelsFetch();
} }

View File

@ -18,6 +18,7 @@ function appReducer(state = initialState, action) {
case MODELS_FETCH: case MODELS_FETCH:
return state.set('loading', true); return state.set('loading', true);
case MODELS_FETCH_SUCCEEDED: case MODELS_FETCH_SUCCEEDED:
console.log('ok');
return state return state
.set('loading', false) .set('loading', false)
.set('models', List(action.models.models)); .set('models', List(action.models.models));

View File

@ -2,7 +2,7 @@ import { takeLatest } from 'redux-saga';
import { LOCATION_CHANGE } from 'react-router-redux'; import { LOCATION_CHANGE } from 'react-router-redux';
import { call, take, put, fork, cancel } from 'redux-saga/effects'; import { call, take, put, fork, cancel } from 'redux-saga/effects';
import request from 'utils/request'; import request from 'utils/request';
import { MODELS_FETCH } from './constants'; import { MODELS_FETCH, MODELS_FETCH_SUCCEEDED } from './constants';
import { modelsFetchSucceeded } from './actions'; import { modelsFetchSucceeded } from './actions';
export function* fetchModels() { export function* fetchModels() {
@ -10,7 +10,7 @@ export function* fetchModels() {
const requestUrl = '/content-type-builder/models'; const requestUrl = '/content-type-builder/models';
const data = yield call(request, requestUrl, { method: 'GET' }); const data = yield call(request, requestUrl, { method: 'GET' });
console.log('data', data);
yield put(modelsFetchSucceeded(data)); yield put(modelsFetchSucceeded(data));
} catch(error) { } catch(error) {
@ -25,7 +25,7 @@ export function* defaultSaga() {
const loadModelsWatcher = yield fork(takeLatest, MODELS_FETCH, fetchModels); const loadModelsWatcher = yield fork(takeLatest, MODELS_FETCH, fetchModels);
// Suspend execution until location changes // Suspend execution until location changes
yield take(LOCATION_CHANGE); yield take(MODELS_FETCH_SUCCEEDED);
yield cancel(loadModelsWatcher); yield cancel(loadModelsWatcher);
} }