mirror of
https://github.com/strapi/strapi.git
synced 2025-12-14 08:44:16 +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';
|
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,
|
||||||
|
|||||||
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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));
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user