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