Почему redux-api-middleware не хранит ответ в State? - PullRequest
0 голосов
/ 22 мая 2019

Я установил redux-api-middleware в этом проекте, над которым я работаю. Кажется, все работает, и я не получаю никаких ошибок, но моя полезная нагрузка не сохраняется в состоянии. Я что-то здесь упускаю?

Я не получаю никаких ошибок от выборки, это просто не возвращает мне ничего.

Действие

import { API_HOST } from '../../constants';

//Pipeline Constants
export const pipelineConstants = {
  FETCH_PIPELINES: 'FETCH_PIPELINES',
  FETCH_PIPELINES_SUCCESS: 'FETCH_PIPELINES_SUCCESS',
  FETCH_PIPELINE_FAILURE: 'FETCH_PIPELINES_FAILURE' 
};

//Fetch Pipeline with redux-api-middleware
export const fetchPipelines = oAuthToken => ({
  //The parameters of the API call are specified by root properties of the [RSAA] property of an RSAA.
  [RSAA]: {
    endpoint: `${API_HOST}/config_api/index`,
    method: 'GET',
    headers: {
      authorization: oAuthToken
    },
    credentials: 'include',
    types: ['FETCH_PIPELINES', 'FETCH_PIPELINES_SUCCESS', 'FETCH_PIPELINES_FAILURE'],
  }
});

1008 * Переходник *


const INITIAL_STATE = {
  pipelines: [],
  expanded: false
};

const { FETCH_PIPELINES, FETCH_PIPELINES_SUCCESS, FETCH_PIPELINES_FAILURE } = pipelineConstants;

const pipelineReducer = (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case FETCH_PIPELINES:
      return Object.assign({}, state, {
        isFetching: true,
        didInvalidate: false
      });
    case FETCH_PIPELINES_SUCCESS:
      return Object.assign({}, state, {
        isFetching: false,
        didInvalidate: false,
        pipelines: action.payload
      });
    case FETCH_PIPELINES_FAILURE:
      return Object.assign({}, state, {
        isFetching: false,
        didInvalidate: true,
      });
    default:
      return state;
  }
};

export default pipelineReducer;

Компонент, который отправляет действие

import PropTypes, { func } from 'prop-types';
import { connect } from 'react-redux';
import { compose } from 'redux';

import { fetchPipelines } from '../../redux/actions/pipelineActions/pipelineActions';

// Data container for the pipelines component, handles data for the pipelines component
const PipelineData = WrappedComponent => {
  return class extends Component {
    componentDidMount() {
      const { dispatch, oAuthToken } = this.props;
      dispatch(fetchPipelines(oAuthToken));
    }

    render() {
      return <WrappedComponent {...this.props} />;
    }
  };
};

const mapStateToProps = state => {
  return {
    oAuthToken: state.userReducer.oAuthToken,
    isLoggedIn: state.pipelineReducer.isLoggedIn,
    pipelines: state.pipelineReducer.pipelines,
    expanded: state.pipelineReducer.expanded
  };
};

const composedPipelineData = compose(
  connect(mapStateToProps),
  PipelineData
);

export default composedPipelineData;

PipelineData.propTypes = {
  dispatch: func,
  oAuthToken: PropTypes.string
};
...