Optimized render

This commit is contained in:
Chi Vinh Le
2017-09-05 00:16:27 +07:00
parent 123935c8bc
commit 07f5f42870
2 changed files with 20 additions and 1 deletions
+1
View File
@@ -7,4 +7,5 @@ export {
capitalize,
getErrorMessages,
getDefinitionName,
getShallowChanges,
} from 'coral-framework/utils';
@@ -4,10 +4,28 @@ import {bindActionCreators} from 'redux';
import AuthorName from '../components/AuthorName';
import {setContentSlot, resetContentSlot, openMenu, closeMenu} from '../actions';
import {compose, gql} from 'react-apollo';
import {getSlotFragmentSpreads} from 'plugin-api/beta/client/utils';
import {getSlotFragmentSpreads, getShallowChanges} from 'plugin-api/beta/client/utils';
class AuthorNameContainer extends React.Component {
shouldComponentUpdate(nextProps) {
// Specifically handle `showMenuForComment` if it is the only change.
const changes = getShallowChanges(this.props, nextProps);
if (changes.length === 1 && changes[0] === 'showMenuForComment') {
const commentId = this.props.comment.id;
if (
commentId !== this.props.showMenuForComment &&
commentId !== nextProps.showMenuForComment
) {
return false;
}
}
// Prevent Slot from rerendering when no props has shallowly changed.
return changes.length !== 0;
}
toggleMenu = () => {
if (this.props.showMenuForComment === this.props.comment.id) {
this.props.closeMenu();