1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-13 11:05:55 +00:00

Made the page contianer update state based on page index rather than scroll valuable, should greatly reduce re-renders.

This commit is contained in:
Scott Tolksdorf
2016-04-06 11:31:11 -04:00
parent 6f4d71083c
commit 207aa87253
2 changed files with 5 additions and 9 deletions

View File

@@ -14,28 +14,24 @@ var PageContainer = React.createClass({
},
getInitialState: function() {
return {
scrollPosition: 0
viewablePageIndex: 0
};
},
handleScroll : function(e){
this.setState({
scrollPosition : e.target.scrollTop
viewablePageIndex : Math.floor(e.target.scrollTop / PAGE_HEIGHT)
});
},
getViewablePageIndex : function(){
return Math.floor(this.state.scrollPosition / PAGE_HEIGHT);
},
renderDummyPage : function(key){
return <div className='phb' key={key}>
yo dawg
<i className='fa fa-spinner fa-spin' />
</div>
},
renderPages : function(){
var currentIndex = this.getViewablePageIndex();
var currentIndex = this.state.viewablePageIndex;
return _.map(this.props.text.split('\\page'), (pageText, index) => {
if(currentIndex - 1 == index || currentIndex == index || currentIndex + 1 == index){
return <div className='phb' dangerouslySetInnerHTML={{__html:Markdown(pageText)}} key={index} />

View File

@@ -1,7 +1,7 @@
{
"name": "naturalCrit",
"description": "A super rad project!",
"version": "1.4.0",
"version": "1.4.1",
"scripts": {
"postinstall": "gulp prod",
"start": "node server.js"