Fixed react warning issue with setState in RHS

Этот коммит содержится в:
Reed Garmsen
2015-12-10 12:30:38 -08:00
родитель 53b0cd8f2a
Коммит 24f422dde3

Просмотреть файл

@@ -17,6 +17,8 @@ export default class RhsThread extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.mounted = false;
this.onChange = this.onChange.bind(this); this.onChange = this.onChange.bind(this);
this.onChangeAll = this.onChangeAll.bind(this); this.onChangeAll = this.onChangeAll.bind(this);
this.forceUpdateInfo = this.forceUpdateInfo.bind(this); this.forceUpdateInfo = this.forceUpdateInfo.bind(this);
@@ -50,8 +52,11 @@ export default class RhsThread extends React.Component {
PostStore.addSelectedPostChangeListener(this.onChange); PostStore.addSelectedPostChangeListener(this.onChange);
PostStore.addChangeListener(this.onChangeAll); PostStore.addChangeListener(this.onChangeAll);
PreferenceStore.addChangeListener(this.forceUpdateInfo); PreferenceStore.addChangeListener(this.forceUpdateInfo);
this.resize(); this.resize();
window.addEventListener('resize', this.handleResize); window.addEventListener('resize', this.handleResize);
this.mounted = true;
} }
componentDidUpdate() { componentDidUpdate() {
if ($('.post-right__scroll')[0]) { if ($('.post-right__scroll')[0]) {
@@ -63,7 +68,10 @@ export default class RhsThread extends React.Component {
PostStore.removeSelectedPostChangeListener(this.onChange); PostStore.removeSelectedPostChangeListener(this.onChange);
PostStore.removeChangeListener(this.onChangeAll); PostStore.removeChangeListener(this.onChangeAll);
PreferenceStore.removeChangeListener(this.forceUpdateInfo); PreferenceStore.removeChangeListener(this.forceUpdateInfo);
window.removeEventListener('resize', this.handleResize); window.removeEventListener('resize', this.handleResize);
this.mounted = false;
} }
forceUpdateInfo() { forceUpdateInfo() {
if (this.state.postList) { if (this.state.postList) {
@@ -82,7 +90,7 @@ export default class RhsThread extends React.Component {
} }
onChange() { onChange() {
var newState = this.getStateFromStores(); var newState = this.getStateFromStores();
if (!Utils.areObjectsEqual(newState, this.state)) { if (this.mounted && !Utils.areObjectsEqual(newState, this.state)) {
this.setState(newState); this.setState(newState);
} }
} }
@@ -120,7 +128,7 @@ export default class RhsThread extends React.Component {
} }
var newState = this.getStateFromStores(); var newState = this.getStateFromStores();
if (!Utils.areObjectsEqual(newState, this.state)) { if (this.mounted && !Utils.areObjectsEqual(newState, this.state)) {
this.setState(newState); this.setState(newState);
} }
} }