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