Added more comments and did cosmetic refactoring to understand code easier

Этот коммит содержится в:
nickago
2015-07-31 17:20:38 -07:00
родитель ea4250bbbc
Коммит f9070177c1

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

@@ -93,6 +93,9 @@ module.exports = React.createClass({
} }
}); });
// scrollPosistion records and holds every position that the user has been at
// Disabled by preventScrollTrigger
// Consider storing this in localStorage instead
$(post_holder).scroll(function(e){ $(post_holder).scroll(function(e){
if (!self.preventScrollTrigger) { if (!self.preventScrollTrigger) {
self.scrollPosition = $(post_holder).scrollTop() + $(post_holder).innerHeight(); self.scrollPosition = $(post_holder).scrollTop() + $(post_holder).innerHeight();
@@ -154,25 +157,26 @@ module.exports = React.createClass({
if (this.gotMorePosts) { if (this.gotMorePosts) {
this.gotMorePosts = false; this.gotMorePosts = false;
$(post_holder).scrollTop($(post_holder).scrollTop() + (post_holder.scrollHeight-this.oldScrollHeight) ); $(post_holder).scrollTop($(post_holder).scrollTop() + (post_holder.scrollHeight-this.oldScrollHeight) );
} else { } else if ($("#new_message")[0] && !this.scrolledToNew) {
if ($("#new_message")[0] && !this.scrolledToNew) {
$(post_holder).scrollTop($(post_holder).scrollTop() + $("#new_message").offset().top - 63); $(post_holder).scrollTop($(post_holder).scrollTop() + $("#new_message").offset().top - 63);
this.scrolledToNew = true; this.scrolledToNew = true;
} else { } else {
$(post_holder).scrollTop(post_holder.scrollHeight); $(post_holder).scrollTop(post_holder.scrollHeight);
} }
}
$(post_holder).perfectScrollbar('update'); $(post_holder).perfectScrollbar('update');
}, },
_onChange: function() { _onChange: function() {
var newState = getStateFromStores(); var newState = getStateFromStores();
if (!utils.areStatesEqual(newState, this.state)) { if (!utils.areStatesEqual(newState, this.state)) {
if (this.state.post_list && this.state.post_list.order) { if (this.state.post_list &&
if (this.state.channel.id === newState.channel.id && this.state.post_list.order.length != newState.post_list.order.length && newState.post_list.order.length > Constants.POST_CHUNK_SIZE) { this.state.post_list.order &&
this.state.channel.id === newState.channel.id &&
this.state.post_list.order.length !== newState.post_list.order.length &&
newState.post_list.order.length > Constants.POST_CHUNK_SIZE) {
// Thus marking the end of the conditional
this.gotMorePosts = true; this.gotMorePosts = true;
} }
}
if (this.state.channel.id !== newState.channel.id) { if (this.state.channel.id !== newState.channel.id) {
this.scrolledToNew = false; this.scrolledToNew = false;
} }