Changeset 5024 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/page/index.jsx
- Timestamp:
- 03/01/2017 06:08:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/page/index.jsx
r4223 r5024 1 import React from 'react'; 1 /** 2 * External dependencies. 3 */ 4 import React, { Component, PropTypes } from 'react'; 2 5 import { connect } from 'react-redux'; 3 import find from 'lodash/find';4 6 5 7 /** … … 7 9 */ 8 10 import Page from './page'; 9 import { getPage } from 'actions';11 import { fetchPage } from 'state/pages/actions'; 10 12 11 const PageContainer = React.createClass( { 13 class PageContainer extends Component { 14 static propTypes = { 15 fetchPage: PropTypes.func, 16 route: PropTypes.object.isRequired, 17 }; 18 19 static defaultProps = { 20 fetchPage: () => {}, 21 }; 22 12 23 componentDidMount() { 13 this. getPage();14 } ,24 this.fetchPage(); 25 } 15 26 16 componentDidUpdate( previousProps) {17 if ( this.props.route.path !== previousProps.route.path ) {18 this. getPage();27 componentDidUpdate( { route } ) { 28 if ( this.props.route.path !== route.path ) { 29 this.fetchPage(); 19 30 } 20 } ,31 } 21 32 22 getPage() {23 this.props. dispatch( getPage( this.props.route.path ));24 } ,33 fetchPage() { 34 this.props.fetchPage( this.props.route.path ); 35 } 25 36 26 37 render() { 27 return <Page { ...this.props }/>;38 return <Page />; 28 39 } 29 } );40 } 30 41 31 const mapStateToProps = ( state, ownProps ) => ( { 32 page: find( state.pages, { slug: ownProps.route.path } ) 33 } ); 34 35 export default connect( mapStateToProps )( PageContainer ); 42 export default connect( 43 null, 44 { 45 fetchPage, 46 } 47 )( PageContainer );
Note: See TracChangeset
for help on using the changeset viewer.