react-virtuallist
Advanced tools
Comparing version 0.0.3 to 0.0.4
/** @jsx React.DOM */ | ||
module.exports = function(React) { | ||
module.exports = function(React, addons) { | ||
var List = React.createClass({displayName: 'List', | ||
@@ -43,3 +43,13 @@ setDimensions: function(props) { | ||
scrolled: 0, | ||
viewLength: isNumber ? this.props.horizontal ? this.props.width : this.props.height : 1000 | ||
viewLength: isNumber ? this.props.horizontal ? this.props.width : this.props.height : 1000 , | ||
defaultProps: { | ||
itemContainer: true, | ||
items: true, | ||
itemLength: true, | ||
width: true, | ||
height: true, | ||
marginFactor: true, | ||
onEvent: true, | ||
horizontal: true | ||
} | ||
} | ||
@@ -49,2 +59,4 @@ }, | ||
var currentScroll = this.refs.list.getDOMNode()[this.props.horizontal ? 'scrollLeft' : 'scrollTop']; | ||
/*if (this.props.onScroll) | ||
this.props.onScroll(currentScroll);*/ | ||
if (Math.abs(currentScroll - this.state.scrolled) >= this.state.viewLength * this.props.marginFactor) | ||
@@ -54,2 +66,4 @@ this.setState({scrolled: currentScroll}); | ||
render: function() { | ||
console.log('render the list'); | ||
var self = this; | ||
var first = Math.max(Math.floor((this.state.scrolled - this.state.viewLength * this.props.marginFactor) / this.props.itemLength), 0) | ||
@@ -59,11 +73,20 @@ var last = Math.min(Math.ceil((this.state.scrolled + this.state.viewLength * (this.props.marginFactor + 1)) / this.props.itemLength), this.props.items.length); | ||
for (var i = first, l = last; i < l; i++) { | ||
items.push(this.props.itemContainer({ | ||
data: this.props.items[i], | ||
key: i, | ||
style: { | ||
position: 'absolute', | ||
top: this.props.horizontal ? 0 : i * this.props.itemLength, | ||
left: this.props.horizontal ? i * this.props.itemLength : 0 | ||
} | ||
})); | ||
var props = {}; | ||
Object.keys(this.props).forEach(function(prop) { | ||
if (!(prop in self.state.defaultProps)) | ||
props[prop] = self.props[prop]; | ||
}); | ||
if (this.props.items[i] instanceof Object && !(this.props.items[i] instanceof Array)) | ||
for (var prop in this.props.items[i]) | ||
props[prop] = this.props.items[i][prop]; | ||
else | ||
props.data = this.props.items[i]; | ||
props.key = i; | ||
props.style = { | ||
position: 'absolute', | ||
top: this.props.horizontal ? 0 : i * this.props.itemLength, | ||
left: this.props.horizontal ? i * this.props.itemLength : 0 | ||
}; | ||
props.onEvent = this.props.onEvent; | ||
items.push(this.props.itemContainer(props)); | ||
} | ||
@@ -70,0 +93,0 @@ return ( |
/** @jsx React.DOM */ | ||
module.exports = function(React) { | ||
module.exports = function(React, addons) { | ||
var List = React.createClass({ | ||
@@ -43,3 +43,13 @@ setDimensions: function(props) { | ||
scrolled: 0, | ||
viewLength: isNumber ? this.props.horizontal ? this.props.width : this.props.height : 1000 | ||
viewLength: isNumber ? this.props.horizontal ? this.props.width : this.props.height : 1000 , | ||
defaultProps: { | ||
itemContainer: true, | ||
items: true, | ||
itemLength: true, | ||
width: true, | ||
height: true, | ||
marginFactor: true, | ||
onEvent: true, | ||
horizontal: true | ||
} | ||
} | ||
@@ -49,2 +59,4 @@ }, | ||
var currentScroll = this.refs.list.getDOMNode()[this.props.horizontal ? 'scrollLeft' : 'scrollTop']; | ||
/*if (this.props.onScroll) | ||
this.props.onScroll(currentScroll);*/ | ||
if (Math.abs(currentScroll - this.state.scrolled) >= this.state.viewLength * this.props.marginFactor) | ||
@@ -54,2 +66,4 @@ this.setState({scrolled: currentScroll}); | ||
render: function() { | ||
console.log('render the list'); | ||
var self = this; | ||
var first = Math.max(Math.floor((this.state.scrolled - this.state.viewLength * this.props.marginFactor) / this.props.itemLength), 0) | ||
@@ -59,11 +73,20 @@ var last = Math.min(Math.ceil((this.state.scrolled + this.state.viewLength * (this.props.marginFactor + 1)) / this.props.itemLength), this.props.items.length); | ||
for (var i = first, l = last; i < l; i++) { | ||
items.push(this.props.itemContainer({ | ||
data: this.props.items[i], | ||
key: i, | ||
style: { | ||
position: 'absolute', | ||
top: this.props.horizontal ? 0 : i * this.props.itemLength, | ||
left: this.props.horizontal ? i * this.props.itemLength : 0 | ||
} | ||
})); | ||
var props = {}; | ||
Object.keys(this.props).forEach(function(prop) { | ||
if (!(prop in self.state.defaultProps)) | ||
props[prop] = self.props[prop]; | ||
}); | ||
if (this.props.items[i] instanceof Object && !(this.props.items[i] instanceof Array)) | ||
for (var prop in this.props.items[i]) | ||
props[prop] = this.props.items[i][prop]; | ||
else | ||
props.data = this.props.items[i]; | ||
props.key = i; | ||
props.style = { | ||
position: 'absolute', | ||
top: this.props.horizontal ? 0 : i * this.props.itemLength, | ||
left: this.props.horizontal ? i * this.props.itemLength : 0 | ||
}; | ||
props.onEvent = this.props.onEvent; | ||
items.push(this.props.itemContainer(props)); | ||
} | ||
@@ -70,0 +93,0 @@ return ( |
{ | ||
"name": "react-virtuallist", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "React component for rendering virtual lists", | ||
@@ -5,0 +5,0 @@ "main": "js/virtuallist.js", |
664998
60
18106