<commit_before>/*
 *   This file is part of 6502.ts, an emulator for 6502 based systems built
 *   in Typescript.
 *
 *   Copyright (C) 2014 - 2017 <NAME> & contributors
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import * as React from 'react';

interface State {
    id: string;
    index: number;
}

class FileUploadButton extends React.Component<FileUploadButton.Props, State> {

    render() {
        return <div className='btn btn-default' style={{display: 'inline-block'}}>
            <label htmlFor={this.state.id}>{this.props.children}</label>
            <input
                accept={this.props.accept}
                type='file'
                id={this.state.id}
                style={{display: 'none'}}
                onChange={this._onChange.bind(this)}
                key={this.state.index}
            />
        </div>;
    }

    private _onChange(e: Event) {
        this.props.onFilesSelected((e.currentTarget as HTMLInputElement).files);

        // Recreate the input node in order to allow subsequent uploads of the same file
        this.setState({index: this.state.index + 1});
    }

    state: State = {
        id: `file_upload_${Math.floor(Math.random() * 10000000)}`,
        index: 1
    };

}

namespace FileUploadButton {

    export interface Props {
        accept?: string;
        onFilesSelected?: (files: FileList) => void;
    }

    export const defaultProps: Props = {
        onFilesSelected: () => undefined
    };

}

export default FileUploadButton;<commit_msg>Fix potential race in setState.<commit_after>/*
 *   This file is part of 6502.ts, an emulator for 6502 based systems built
 *   in Typescript.
 *
 *   Copyright (C) 2014 - 2017 <NAME> & contributors
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import * as React from 'react';

interface State {
    id: string;
    index: number;
}

class FileUploadButton extends React.Component<FileUploadButton.Props, State> {

    render() {
        return <div className='btn btn-default' style={{display: 'inline-block'}}>
            <label htmlFor={this.state.id}>{this.props.children}</label>
            <input
                accept={this.props.accept}
                type='file'
                id={this.state.id}
                style={{display: 'none'}}
                onChange={this._onChange.bind(this)}
                key={this.state.index}
            />
        </div>;
    }

    private _onChange(e: Event) {
        this.props.onFilesSelected((e.currentTarget as HTMLInputElement).files);

        // Recreate the input node in order to allow subsequent uploads of the same file
        this.setState(
            (prevState: State) => ({
                index: prevState.index + 1
            })
        );
    }

    state: State = {
        id: `file_upload_${Math.floor(Math.random() * 10000000)}`,
        index: 1
    };

}

namespace FileUploadButton {

    export interface Props {
        accept?: string;
        onFilesSelected?: (files: FileList) => void;
    }

    export const defaultProps: Props = {
        onFilesSelected: () => undefined
    };

}

export default FileUploadButton;
{'fraction_non_alphanumeric': 0.0973724884080371, 'fraction_numerical': 0.016780746301611835, 'mean_word_length': 2.4422492401215807, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5936543', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1210, 'n_words': 444}