save prev reply cb to store for preventing bulk rerender on reply click

This commit is contained in:
igoradamenko
2018-05-13 02:06:35 +03:00
parent 28f279f41a
commit c4d5766340
3 changed files with 8 additions and 19 deletions
+7 -6
View File
@@ -65,15 +65,16 @@ export default class Comment extends Component {
toggleInputVisibility() {
const { isInputVisible } = this.state;
const onPrevReplyCb = store.get('onPrevReplyCb');
this.setState({ isInputVisible: !isInputVisible });
if (this.props.onReplyClick) {
if (!isInputVisible) {
this.props.onReplyClick(() => this.setState({ isInputVisible: false }));
} else {
this.props.onReplyClick(null);
}
if (onPrevReplyCb) onPrevReplyCb();
if (!isInputVisible) {
store.set('onPrevReplyCb', () => this.setState({ isInputVisible: false }));
} else {
store.set('onPrevReplyCb', null);
}
}
-10
View File
@@ -39,7 +39,6 @@ export default class Root extends Component {
this.onSignOut = this.onSignOut.bind(this);
this.onBlockedUsersShow = this.onBlockedUsersShow.bind(this);
this.onBlockedUsersHide = this.onBlockedUsersHide.bind(this);
this.onReplyClick = this.onReplyClick.bind(this);
this.onSortChange = this.onSortChange.bind(this);
this.onUnblockSomeone = this.onUnblockSomeone.bind(this);
this.checkUrlHash = this.checkUrlHash.bind(this);
@@ -139,14 +138,6 @@ export default class Root extends Component {
});
}
onReplyClick(cb) {
if (this.onPrevReplyClickCallback) {
this.onPrevReplyClickCallback();
}
this.onPrevReplyClickCallback = cb;
}
onSortChange(sort) {
if (sort === this.state.sort) return;
@@ -247,7 +238,6 @@ export default class Root extends Component {
mods={{ level: 0 }}
data={thread}
onReply={this.addComment}
onReplyClick={this.onReplyClick}
/>
))
}
+1 -3
View File
@@ -19,7 +19,7 @@ export default class Thread extends Component {
}
render(props, { collapsed }) {
const { data: { comment, replies = [] }, mix, mods = {}, onReplyClick } = props;
const { data: { comment, replies = [] }, mix, mods = {} } = props;
return (
<div className={b('thread', props)}>
@@ -27,7 +27,6 @@ export default class Thread extends Component {
data={comment}
mods={{ level: mods.level, collapsed, collapsible: !!replies.length }}
onReply={props.onReply}
onReplyClick={onReplyClick}
onCollapseToggle={this.onCollapseToggle}
/>
@@ -37,7 +36,6 @@ export default class Thread extends Component {
data={thread}
mods={{ level: mods.level < 5 ? mods.level + 1 : mods.level }}
onReply={props.onReply}
onReplyClick={onReplyClick}
/>
))
}