<commit_before>import React, { Component, PropTypes } from 'react';
import LogDisplay from './LogDisplay';
import Button from './Button';
import timeFormat from '../utils/timeFormat';
export default class TimeDisplay extends Component {

    static propTypes = {
        time: PropTypes.number.required
    }

    state = {
        time: 0,
        on: false,
        log: [],
        quote: Math.floor(Math.random() * 5 + 1)
    };

    timer = '';

    logTime(newTime) {
        // this.state.log.push(this.state.time);
        // this.setState({
        // 	log: this.state.log
        // });
        this.setState({
        	log: [this.state.time, ...this.state.log]
        })
    }

    clearTime() {
        this.setState({
            log: [],
            quote: Math.floor(Math.random() * 5 + 1)
        })
    }

    toggleOn() {
        if (this.state.on) {
            clearInterval(this.timer);
        } else {
            this.timer = setInterval(() => {
                this.setState({ time: this.state.time + 1 })
            }, 10);
        }
        this.setState({<commit_msg>添加计时器的键盘事件（嵌入式开发）<commit_after>import React, { Component, PropTypes } from 'react';
import LogDisplay from './LogDisplay';
import Button from './Button';
import timeFormat from '../utils/timeFormat';
export default class TimeDisplay extends Component {

    static propTypes = {
        time: PropTypes.number.required
    }

    state = {
        time: 0,
        on: false,
        log: [],
        quote: Math.floor(Math.random() * 5 + 1)
    };

    timer = '';

    componentDidMount(){
    	this.keyCommands();
    }

    componentWillUnmount(){
    	window.removeEvnetListener('keyup');
    	window.removeEvnetListener('keydown');
    }

    // 案件？嵌入式开发
    keyCommands = () => {
    	window.addEventListener('keydown', e => e.preventDefault());
    	window.addEventListener('keyup', e => {
    		e.preventDefault();
    		switch(e.keyCode){
    			// Space
    			case 32:
	    			this.toggleOn();
	    			break;
	    		// R
	    		case 82:
	    			this.resetTime();
	    			break;
	    		// L
	    		case 72:
	    			this.logTime();
	    			break;
	    		// Enter
	    		case 13:
	    			this.clearTime();
	    			break;
	    		default:
	    			return;
    		}
    	});

    }

    logTime(newTime) {
        // this.state.log.push(this.state.time);
        // this.setState({
        // 	log: this.state.log
        // });
        this.setState({
        	log: [this.state.time, ...this.state.log]
        })
    }

    clearTime() {
        this.setState({
            log: [],
            quote: Math.floor(Math.random() * 5 + 1)
        })
    }

    toggleOn() {
        if (this.state.on) {
            clearInterval(this.timer);
        } else {
            this.timer = setInterval(() => {
                this.setState({ time: this.state.time + 1 })
            }, 10);
        }
        this.setState({
{'fraction_non_alphanumeric': 0.14804660726525018, 'fraction_numerical': 0.00822481151473612, 'mean_word_length': 1.5763459841129743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2389393', 'n_tokens_mistral': 971, 'n_tokens_neox': 928, 'n_words': 171}