mirror of
https://github.com/strapi/strapi.git
synced 2025-12-10 14:34:22 +00:00
Fix app sagas in charge of fetching models
This commit is contained in:
parent
e29cbfdab2
commit
6a7ca0c005
@ -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,
|
||||
|
||||
@ -24,6 +24,7 @@ define(map(messages, (message, id) => ({
|
||||
|
||||
class App extends React.Component {
|
||||
componentDidMount() {
|
||||
console.log('did mount');
|
||||
this.props.modelsFetch();
|
||||
}
|
||||
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -65,4 +65,4 @@
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user