mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-03 19:36:20 +00:00 
			
		
		
		
	Clean component by removing useless state logic
This commit is contained in:
		
							parent
							
								
									8d8c4f0fac
								
							
						
					
					
						commit
						708eb7b6e7
					
				@ -1,28 +1,3 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Actions
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  LOAD,
 | 
			
		||||
  LOAD_SUCCESS
 | 
			
		||||
} from './constants';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Load the generalSettings, this action starts the request saga
 | 
			
		||||
 *
 | 
			
		||||
 * @return {object} An action object with a type of LOAD_GENERAL_SETTINGS
 | 
			
		||||
 */
 | 
			
		||||
export function load_success(data) {
 | 
			
		||||
  console.log('load_success() called');
 | 
			
		||||
  return {
 | 
			
		||||
    type: LOAD_SUCCESS,
 | 
			
		||||
    data
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function load() {
 | 
			
		||||
  console.log('load() called');
 | 
			
		||||
  return {
 | 
			
		||||
    type: LOAD
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,3 @@
 | 
			
		||||
 * Follow this format:
 | 
			
		||||
 * export const YOUR_ACTION_CONSTANT = 'your-plugin/YourContainer/YOUR_ACTION_CONSTANT';
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
export const LOAD_SUCCESS = 'contentManager/HomePage/LOAD_SUCCESS';
 | 
			
		||||
export const LOAD = 'contentManager/HomePage/LOAD';
 | 
			
		||||
 | 
			
		||||
@ -10,20 +10,8 @@ import { injectIntl } from 'react-intl';
 | 
			
		||||
 | 
			
		||||
import styles from './styles.scss';
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  load,
 | 
			
		||||
} from './actions';
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  selectName
 | 
			
		||||
} from './selectors';
 | 
			
		||||
 | 
			
		||||
export class HomePage extends React.Component {
 | 
			
		||||
 | 
			
		||||
  componentWillMount() {
 | 
			
		||||
    this.props.load();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  render() {
 | 
			
		||||
    return (
 | 
			
		||||
      <div>
 | 
			
		||||
@ -40,18 +28,11 @@ export class HomePage extends React.Component {
 | 
			
		||||
 | 
			
		||||
HomePage.propTypes = {};
 | 
			
		||||
 | 
			
		||||
export function mapDispatchToProps(dispatch) {
 | 
			
		||||
  return {
 | 
			
		||||
    load: () => {
 | 
			
		||||
      console.log('dispatch LOAD');
 | 
			
		||||
      dispatch(load());
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
export function mapDispatchToProps() {
 | 
			
		||||
  return {};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const mapStateToProps = createStructuredSelector({
 | 
			
		||||
  name: selectName()
 | 
			
		||||
});
 | 
			
		||||
const mapStateToProps = createStructuredSelector({});
 | 
			
		||||
 | 
			
		||||
// Wrap the component to inject dispatch and state into it
 | 
			
		||||
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(HomePage));
 | 
			
		||||
 | 
			
		||||
@ -12,23 +12,11 @@
 | 
			
		||||
 | 
			
		||||
import { fromJS } from 'immutable';
 | 
			
		||||
 | 
			
		||||
import { LOAD, LOAD_SUCCESS } from './constants';
 | 
			
		||||
 | 
			
		||||
// The initial state of the App
 | 
			
		||||
const initialState = fromJS({
 | 
			
		||||
  loading: false,
 | 
			
		||||
  name: null
 | 
			
		||||
});
 | 
			
		||||
const initialState = fromJS({});
 | 
			
		||||
 | 
			
		||||
function appReducer(state = initialState, action) {
 | 
			
		||||
  switch (action.type) {
 | 
			
		||||
    case LOAD:
 | 
			
		||||
      return state
 | 
			
		||||
        .set('loading', true);
 | 
			
		||||
    case LOAD_SUCCESS:
 | 
			
		||||
      return state
 | 
			
		||||
        .set('name', action.data.name)
 | 
			
		||||
        .set('loading', false);
 | 
			
		||||
    default:
 | 
			
		||||
      return state;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -25,6 +25,4 @@ export function* mySaga() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Bootstrap sagas
 | 
			
		||||
export default [
 | 
			
		||||
  mySaga
 | 
			
		||||
];
 | 
			
		||||
export default [];
 | 
			
		||||
 | 
			
		||||
@ -2,18 +2,8 @@
 | 
			
		||||
 * The home state selectors
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { createSelector } from 'reselect';
 | 
			
		||||
 | 
			
		||||
const selectHome = (state) => state.get('home');
 | 
			
		||||
 | 
			
		||||
const selectName = () => createSelector(
 | 
			
		||||
  selectHome,
 | 
			
		||||
  (state) => {
 | 
			
		||||
    return state.get('name');
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export {
 | 
			
		||||
  selectHome,
 | 
			
		||||
  selectName,
 | 
			
		||||
  selectHome
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -18,13 +18,11 @@ export default function createRoutes(store) {
 | 
			
		||||
      name: 'home',
 | 
			
		||||
      getComponent(nextState, cb) {
 | 
			
		||||
        const reducer = require('containers/HomePage/reducer'); // eslint-disable-line global-require
 | 
			
		||||
        const sagas = require('containers/HomePage/sagas'); // eslint-disable-line global-require
 | 
			
		||||
        const component = require('containers/HomePage'); // eslint-disable-line global-require
 | 
			
		||||
 | 
			
		||||
        const renderRoute = loadModule(cb);
 | 
			
		||||
 | 
			
		||||
        injectReducer('home', reducer.default);
 | 
			
		||||
        injectSagas(sagas.default);
 | 
			
		||||
        renderRoute(component);
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user