<commit_before>import {fromEvent} from 'rxjs'
import PropTypes from 'prop-types'
import React from 'react'
import _ from 'lodash'

const handlers = []

fromEvent(document, 'keydown')
    .subscribe(
        event => _.find([...handlers], handler => handler(event))
    )

export default class Keybinding extends React.Component {
    handler = null

    constructor(props) {
        super(props)
        this.handler = this.getHandler.bind(this)
    }

    getHandler(event) {
        const {keymap, disabled} = this.props
        if (!disabled) {
            const key = [
                {key: 'Ctrl', value: event.ctrlKey},
                {key: 'Alt', value: event.altKey},
                {key: 'Shift', value: event.shiftKey},
                {key: 'Meta', value: event.metaKey}]
                .filter(({value}) => value)
                .map(({key}) => key)
                .concat([event.key])
                .join('+')
            const handler = keymap[key]
            if (handler) {
                handler(event)
                event.preventDefault()
                return true
            } else if (keymap.default) {
                keymap.default(event)
                event.preventDefault()
                return true
            }
        }
        return false
    }

    addHandler() {
        handlers.unshift(this.handler)
    }

    removeHandler() {
        _.pull(handlers, this.handler)
    }

    render() {
        const {children} = this.props
        return children || null
    }

    componentDidMount() {
        this.addHandler()
    }

    componentWillUnmount() {
        this.removeHandler()
    }
}

Keybinding.propTypes = {
    disabled: PropTypes.any,<commit_msg>Added and removed keybindings when component is enabled/disabled.<commit_after>import {fromEvent} from 'rxjs'
import PropTypes from 'prop-types'
import React from 'react'
import _ from 'lodash'
import {connect} from 'store'

const handlers = []

fromEvent(document, 'keydown')
    .subscribe(
        event => _.find([...handlers], handler => handler(event))
    )

class Keybinding extends React.Component {
    handler = null

    constructor(props) {
        super(props)
        const {onEnable, onDisable} = props
        this.handler = this.getHandler.bind(this)
        onEnable(() => this.addHandler())
        onDisable(() => this.removeHandler())
    }

    getHandler(event) {
        const {keymap, disabled} = this.props
        if (!disabled) {
            const key = [
                {key: 'Ctrl', value: event.ctrlKey},
                {key: 'Alt', value: event.altKey},
                {key: 'Shift', value: event.shiftKey},
                {key: 'Meta', value: event.metaKey}]
                .filter(({value}) => value)
                .map(({key}) => key)
                .concat([event.key])
                .join('+')
            const handler = keymap[key]
            if (handler) {
                handler(event)
                event.preventDefault()
                return true
            } else if (keymap.default) {
                keymap.default(event)
                event.preventDefault()
                return true
            }
        }
        return false
    }

    addHandler() {
        handlers.unshift(this.handler)
    }

    removeHandler() {
        _.pull(handlers, this.handler)
    }

    render() {
        const {children} = this.props
        return children || null
    }

    componentDidMount() {
        this.addHandler()
    }

    componentWillUnmount() {
        this.removeHandler()
    }
}

export default connect()(
    Keybinding
)

Keybinding.propTypes = {
    disabled: PropTypes.any,
{'fraction_non_alphanumeric': 0.1223041223041223, 'fraction_numerical': 0.0, 'mean_word_length': 1.7080561714708056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '519397', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1003, 'n_words': 228}