Changeset 5024 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin-card/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-card/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 PluginCard from './plugin-card'; 9 import { getPlugin } from 'actions'; 11 import { fetchPlugin } from 'state/plugins/actions'; 12 import { getPlugin } from 'state/selectors'; 10 13 11 const PluginCardContainer = React.createClass( { 14 export class PluginCardContainer extends Component { 15 static propTypes = { 16 fetchPlugin: PropTypes.func, 17 plugin: PropTypes.object, 18 slug: PropTypes.string, 19 }; 20 21 static defaultProps = { 22 fetchPlugin: () => {}, 23 plugin: {}, 24 slug: '', 25 }; 26 12 27 componentDidMount() { 13 this. getPlugin();14 } ,28 this.fetchPlugin(); 29 } 15 30 16 componentDidUpdate( previousProps) {17 if ( this.props.slug !== previousProps.slug) {18 this. getPlugin();31 componentDidUpdate( { plugin, slug } ) { 32 if ( this.props.slug !== slug || this.props.plugin !== plugin ) { 33 this.fetchPlugin(); 19 34 } 20 } ,35 } 21 36 22 getPlugin() {23 this.props.dispatch( getPlugin( this.props.slug ));24 } ,37 fetchPlugin() { 38 // this.props.fetchPlugin( this.props.slug ); 39 } 25 40 26 41 render() { 27 return <PluginCard { ...this.props} />;42 return <PluginCard plugin={ this.props.plugin } />; 28 43 } 29 } );44 } 30 45 31 const mapStateToProps = ( state, ownProps ) => ( { 32 plugin: find( state.plugins, { slug: ownProps.slug } ) 33 } ); 34 35 export default connect( mapStateToProps )( PluginCardContainer ); 36 37 46 export default connect( 47 ( state, { plugin, slug } ) => ( { 48 plugin: plugin || getPlugin( state, slug ), 49 } ), 50 { 51 fetchPlugin, 52 }, 53 )( PluginCardContainer );
Note: See TracChangeset
for help on using the changeset viewer.