fixed missing ifmounted bug / fixed getting item when navigating directly to page

This commit is contained in:
Senad Uka
2015-01-28 05:04:45 +01:00
parent f27c29fccf
commit f8b3ef3a64
9 changed files with 109 additions and 92 deletions

View File

@@ -1,6 +1,7 @@
var React = require('react'),
ItemMultiMediaDescriptions = require('./itemMultiMediaDescriptions'),
ItemActions = require('../../actions/itemActions'),
NavigationStore = require('../../stores/NavigationStore'),
ItemStore = require('../../stores/itemStore');
var Router = require('react-router');
@@ -35,17 +36,21 @@ var ItemWithDetailsPage = React.createClass({
// Add change listeners to stores
componentDidMount: function() {
ItemStore.addChangeListener(this._onChange);
NavigationStore.addChangeListener(this._onChange);
ItemActions.loadItemWithDetails();
},
_onChange: function () {
this.setState({
item: ItemStore.getSelectedItem()
});
if (this.isMounted()) {
this.setState({
item: ItemStore.getLoadedItemWithDetails()
});
}
},
getInitialState: function () {
return {
item : ItemStore.getSelectedItem()
item : ItemStore.getLoadedItemWithDetails()
};
}