<commit_before>var React = require('react');
var ReactDOM = require('react-dom');
var klass = require('../cssClasses');
var outerWidth = require('../dimensions').outerWidth;
var CSSTranslate = require('../CSSTranslate');
var Swipe = require('react-easy-swipe');

// react-swipe was compiled using babel
Swipe = Swipe.default;

module.exports = React.createClass({

    propsTypes: {
        children: React.PropTypes.element.isRequired,
        transitionTime: React.PropTypes.number,
        selectedItem: React.PropTypes.number
    },

    getDefaultProps () {
        return {
            selectedItem: 0,
            transitionTime: 350,
            axis: 'horizontal'
        }
    },

    getInitialState () {
        return {
            selectedItem: this.props.selectedItem,
            hasMount: false,
            firstItem: this.getFirstItem(this.props.selectedItem)
        };
    },

    componentWillReceiveProps (props, state) {
        if (props.selectedItem !== this.state.selectedItem) {
            this.setState({
                selectedItem: props.selectedItem,
                firstItem: this.getFirstItem(props.selectedItem)
            });
        }
    },

    componentWillUnmount() {
        // removing listeners
        window.removeEventListener("resize", this.updateStatics);
        window.removeEventListener("DOMContentLoaded", this.updateStatics);
    },

    componentDidMount (nextProps) {
        // as the widths are calculated, we need to resize
        // the carousel when the window is resized
        window.addEventListener("resize", this.updateStatics);
        // issue #2 - image loading smaller
        window.addEventListener("DOMContentLoaded", this.updateStatics);

        var defaultImg = ReactDOM.findDOMNode(this.thumb0).getElementsByTagName('img')[0];
        defaultImg.addEventListener('load', this.setMountState);

        // when the component is rendered we need to calculate
        // the container size to adjust the responsive behaviour
        this.updateStatics();
    },

    updateStatics () {
        var total = this.props.children.length;
        this.wrapperSize = this.itemsWrapper.clientWidth;
        this.itemSize = outerWidth(this.thumb0);
        this.visibleItems = Math.floor(this.wrapperSize / this.itemSize);
        this.lastPosition = total - this.visibleItems;
        this.showArrows = this.visibleItems < total;
    },

    setMountState () {
        this.setState({hasMount: true});
    },

    handleClickItem (index, item) {
        var handler = this.props.onSelectItem;

        if (typeof handler === 'function') {
            handler(index, item);
        }
    },

    onSwipeStart() {
        this.setState({<commit_msg>#104 - Fixes problem where arrows were not appearing after carousel was loaded<commit_after>var React = require('react');
var ReactDOM = require('react-dom');
var klass = require('../cssClasses');
var outerWidth = require('../dimensions').outerWidth;
var CSSTranslate = require('../CSSTranslate');
var Swipe = require('react-easy-swipe');

// react-swipe was compiled using babel
Swipe = Swipe.default;

module.exports = React.createClass({

    propsTypes: {
        children: React.PropTypes.element.isRequired,
        transitionTime: React.PropTypes.number,
        selectedItem: React.PropTypes.number
    },

    getDefaultProps () {
        return {
            selectedItem: 0,
            transitionTime: 350,
            axis: 'horizontal'
        }
    },

    getInitialState () {
        return {
            selectedItem: this.props.selectedItem,
            hasMount: false,
            firstItem: this.getFirstItem(this.props.selectedItem)
        };
    },

    componentWillReceiveProps (props, state) {
        if (props.selectedItem !== this.state.selectedItem) {
            this.setState({
                selectedItem: props.selectedItem,
                firstItem: this.getFirstItem(props.selectedItem)
            });
        }
    },

    componentDidMount (nextProps) {
        // as the widths are calculated, we need to resize
        // the carousel when the window is resized
        window.addEventListener("resize", this.updateStatics);
        // issue #2 - image loading smaller
        window.addEventListener("DOMContentLoaded", this.updateStatics);

        var defaultImg = this.getDefaultImage();
        if (defaultImg) {
            defaultImg.addEventListener('load', this.onFirstImageLoad);
        }

        // when the component is rendered we need to calculate
        // the container size to adjust the responsive behaviour
        this.updateStatics();
    },

    componentWillUnmount() {
        // removing listeners
        window.removeEventListener("resize", this.updateStatics);
        window.removeEventListener("DOMContentLoaded", this.updateStatics);

        var defaultImg = this.getDefaultImage();
        if (defaultImg) {
            defaultImg.removeEventListener('load', this.onFirstImageLoad);
        }
    },

    updateStatics () {
        var total = this.props.children.length;
        this.wrapperSize = this.itemsWrapper.clientWidth;
        this.itemSize = outerWidth(this.thumb0);
        this.visibleItems = Math.floor(this.wrapperSize / this.itemSize);
        this.lastPosition = total - this.visibleItems;
        this.showArrows = this.visibleItems < total;
    },

    getDefaultImage () {
        var firstItem = ReactDOM.findDOMNode(this.thumb0);

        if (firstItem) {
            var firstImage = firstItem.getElementsByTagName('img');
            return firstImage && firstImage[0];
        }

        return null;
    },

    onFirstImageLoad () {
        this.setState({hasMount: true});
        this.updateStatics();
    },

    handleClickItem (index, item) {
        var handler = this.props.onSelectItem;

        if (typeof handler === 'function') {
            handler(index, item);
        }
    },

    onSwipeStart() {
        this.setState({
{'fraction_non_alphanumeric': 0.1104592691920885, 'fraction_numerical': 0.0031847133757961785, 'mean_word_length': 2.3597972972972974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2726407', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1553, 'n_words': 338}