<commit_before>React = require 'react'
_ = require 'lodash'
mousetrap = require 'mousetrap'

shortcuts = React.createFactory 'shortcuts'

module.exports = React.createClass

  displayName: 'Shortcuts'

  contextTypes:
    shortcuts: React.PropTypes.object.isRequired

  propTypes:
    handler: React.PropTypes.func.isRequired
    name: React.PropTypes.string.isRequired
    element: React.PropTypes.func
    tabIndex: React.PropTypes.number
    className: React.PropTypes.string
    eventType: React.PropTypes.string
    stopPropagation: React.PropTypes.bool

  _element: null

  getDefaultProps: ->
    eventType: null
    stopPropagation: null

  _bindShortcuts: (shortcutsArr) ->
    mousetrap(@_element).bind(shortcutsArr, @_handleShortcuts, @props.eventType)

  _unbindShortcuts: (shortcutsArr) ->
    mousetrap(@_element).unbind(shortcutsArr)

  componentDidMount: ->
    @_element = React.findDOMNode(@refs.shortcuts)

    shortcutsArr = @context.shortcuts.getShortcuts(@props.name)
    @_bindShortcuts(shortcutsArr)

    @context.shortcuts.onUpdate =>
      shortcuts = @context.shortcuts.getShortcuts(@props.name)
      @_unbindShortcuts(shortcutsArr)
      @_bindShortcuts(shortcutsArr)

  componentWillUnmount: ->
    @context.shortcuts.dispose()
    @_unbindShortcuts()

  _handleShortcuts: (e, keyName) ->
    e.preventDefault()
    e.stopPropagation() if @props.stopPropagation
    shortcutName = @context.shortcuts.findShortcutName(keyName)
    @props.handler(shortcutName)

  render: ->
    element = shortcuts
    element = @props.element if _.isFunction(@props.element)

    element
      tabIndex: @props.tabIndex or -1
      className: @props.className<commit_msg>fix typo in shortcuts component<commit_after>React = require 'react'
_ = require 'lodash'
mousetrap = require 'mousetrap'

shortcuts = React.createFactory 'shortcuts'

module.exports = React.createClass

  displayName: 'Shortcuts'

  contextTypes:
    shortcuts: React.PropTypes.object.isRequired

  propTypes:
    handler: React.PropTypes.func.isRequired
    name: React.PropTypes.string.isRequired
    element: React.PropTypes.func
    tabIndex: React.PropTypes.number
    className: React.PropTypes.string
    eventType: React.PropTypes.string
    stopPropagation: React.PropTypes.bool

  _element: null

  getDefaultProps: ->
    eventType: null
    stopPropagation: null

  _bindShortcuts: (shortcutsArr) ->
    mousetrap(@_element).bind(shortcutsArr, @_handleShortcuts, @props.eventType)

  _unbindShortcuts: (shortcutsArr) ->
    mousetrap(@_element).unbind(shortcutsArr)

  componentDidMount: ->
    @_element = React.findDOMNode(@refs.shortcuts)

    shortcutsArr = @context.shortcuts.getShortcuts(@props.name)
    @_bindShortcuts(shortcutsArr)

    @context.shortcuts.onUpdate =>
      shortcutsArr = @context.shortcuts.getShortcuts(@props.name)
      @_unbindShortcuts(shortcutsArr)
      @_bindShortcuts(shortcutsArr)

  componentWillUnmount: ->
    @context.shortcuts.dispose()
    @_unbindShortcuts()

  _handleShortcuts: (e, keyName) ->
    e.preventDefault()
    e.stopPropagation() if @props.stopPropagation
    shortcutName = @context.shortcuts.findShortcutName(keyName)
    @props.handler(shortcutName)

  render: ->
    element = shortcuts
    element = @props.element if _.isFunction(@props.element)

    element
      tabIndex: @props.tabIndex or -1
      className: @props.className
{'fraction_non_alphanumeric': 0.10504573620537032, 'fraction_numerical': 0.0005901445854234287, 'mean_word_length': 4.113122171945701, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4913951', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1071, 'n_words': 175}