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';
export function modelsFetch() {
console.log('fetching models');
return {
type: MODELS_FETCH,
};
}
export function modelsFetchSucceeded(models) {
console.log('succeeded');
return {
type: MODELS_FETCH_SUCCEEDED,
models,

View File

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

View File

@ -18,6 +18,7 @@ function appReducer(state = initialState, action) {
case MODELS_FETCH:
return state.set('loading', true);
case MODELS_FETCH_SUCCEEDED:
console.log('ok');
return state
.set('loading', false)
.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 { call, take, put, fork, cancel } from 'redux-saga/effects';
import request from 'utils/request';
import { MODELS_FETCH } from './constants';
import { MODELS_FETCH, MODELS_FETCH_SUCCEEDED } from './constants';
import { modelsFetchSucceeded } from './actions';
export function* fetchModels() {
@ -10,7 +10,7 @@ export function* fetchModels() {
const requestUrl = '/content-type-builder/models';
const data = yield call(request, requestUrl, { method: 'GET' });
console.log('data', data);
yield put(modelsFetchSucceeded(data));
} catch(error) {
@ -25,7 +25,7 @@ export function* defaultSaga() {
const loadModelsWatcher = yield fork(takeLatest, MODELS_FETCH, fetchModels);
// Suspend execution until location changes
yield take(LOCATION_CHANGE);
yield take(MODELS_FETCH_SUCCEEDED);
yield cancel(loadModelsWatcher);
}

View File

@ -65,4 +65,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}