mirror of
https://github.com/wassname/talk.git
synced 2026-08-04 13:23:35 +08:00
Optimized render
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user