<commit_before>import { h, Component } from 'preact';

const STYLE_INNER = 'position:relative; overflow:hidden; width:100%; min-height:100%;';

const STYLE_CONTENT = 'position:absolute; top:0; left:0; height:100%; width:100%; overflow:visible;';

/** Virtual list, renders only visible items.
 *	@param {Array<*>} data         List of data items
 *	@param {Function} renderRow    Renders a single row
 *	@param {Number} rowHeight      Static height of a row
 *	@param {Number} overscanCount  Amount of rows to render above and below visible area of the list
 *	@param {Boolean} [sync=false]  true forces synchronous rendering
 *	@example
 *		<VirtualList
 *			data={['a', 'b', 'c']}
 *			renderRow={ row => <div>{row}</div> }
 *			rowHeight={22}
 *			sync
 *		/>
 */
export default class VirtualList extends Component {
	resize = () => {
		if (this.state.height!==this.base.offsetHeight) {
			this.setState({ height: this.base.offsetHeight });
		}
	};

	handleScroll = () => {
		this.setState({ offset: this.base.scrollTop });
		if (this.props.sync) this.forceUpdate();
	};

	componentDidUpdate() {
		this.resize();
	}

	componentDidMount() {
		this.resize();
		addEventListener('resize', this.resize);
	}

	componentWillUnmount() {
		removeEventListener('resize', this.resize);
	}

	render({ data, rowHeight, renderRow, overscanCount = 10, ...props }, { offset=0, height=0 }) {
		// first visible row index
		let start = (offset / rowHeight)|0;

		// last visible row index
		let end = start + 1 + (height / rowHeight)|0;

		// data slice currently in viewport plus overscan items
		let selection = data.slice(Math.max(0, start - overscanCount), end + overscanCount);

		return (
			<div onScroll={this.handleScroll} {...props}>
				<div style={`${STYLE_INNER} height:${data.length*rowHeight}px;`}>
					<div style={`${STYLE_CONTENT} top:${start*rowHeight}px;`}>
						{ selection.map(renderRow) }
					</div>
				</div>
			</div>
		);
	}
}<commit_msg>Disable overscan in sync mode<commit_after>import { h, Component } from 'preact';

const STYLE_INNER = 'position:relative; overflow:hidden; width:100%; min-height:100%;';

const STYLE_CONTENT = 'position:absolute; top:0; left:0; height:100%; width:100%; overflow:visible;';

/** Virtual list, renders only visible items.
 *	@param {Array<*>} data         List of data items
 *	@param {Function} renderRow    Renders a single row
 *	@param {Number} rowHeight      Static height of a row
 *	@param {Number} overscanCount  Amount of rows to render above and below visible area of the list
 *	@param {Boolean} [sync=false]  true forces synchronous rendering
 *	@example
 *		<VirtualList
 *			data={['a', 'b', 'c']}
 *			renderRow={ row => <div>{row}</div> }
 *			rowHeight={22}
 *			sync
 *		/>
 */
export default class VirtualList extends Component {
	resize = () => {
		if (this.state.height!==this.base.offsetHeight) {
			this.setState({ height: this.base.offsetHeight });
		}
	};

	handleScroll = () => {
		this.setState({ offset: this.base.scrollTop });
		if (this.props.sync) this.forceUpdate();
	};

	componentDidUpdate() {
		this.resize();
	}

	componentDidMount() {
		this.resize();
		addEventListener('resize', this.resize);
	}

	componentWillUnmount() {
		removeEventListener('resize', this.resize);
	}

	render({ data, rowHeight, renderRow, overscanCount=10, sync, ...props }, { offset=0, height=0 }) {
		// first visible row index
		let start = (offset / rowHeight)|0;

		// last visible row index
		let end = start + 1 + (height / rowHeight)|0;

		if (!sync && overscanCount) {
			start = Math.max(0, start - overscanCount);
			end += overscanCount;
		}

		// data slice currently in viewport plus overscan items
		let selection = data.slice(start, end);

		return (
			<div onScroll={this.handleScroll} {...props}>
				<div style={`${STYLE_INNER} height:${data.length*rowHeight}px;`}>
					<div style={`${STYLE_CONTENT} top:${start*rowHeight}px;`}>
						{ selection.map(renderRow) }
					</div>
				</div>
			</div>
		);
	}
}
{'fraction_non_alphanumeric': 0.16140350877192983, 'fraction_numerical': 0.012030075187969926, 'mean_word_length': 3.802647412755716, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6147206', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1304, 'n_words': 338}