<commit_before>class KDToggleButton extends KDButtonView

  constructor:(options = {}, data)->

    options = $.extend
      dataPath     : null          # a JsPath String
      defaultState : null          # a String
      states       : []            # an Array of Objects in form of stateName : callback key/value pairs
    , options

    super options, data

    @setState options.defaultState

  getStateIndex:(name)->

    {states} = @getOptions()
    unless name
      return 0
    else
      for state, index in states
        if name is state.title
          return index

  decorateState:(name)->
    @setTitle @state.title
    @setIconClass @state.iconClass if @state.iconClass?

  getState:-> @state

  setState:(name)->

    {states} = @getOptions()
    @stateIndex = index = @getStateIndex name
    @state      = states[index]
    @decorateState name

    @setCallback states[index].callback.bind @, @toggleState.bind @

  toggleState:(err)->

    {states} = @getOptions()
    nextState = states[@stateIndex + 1] or states[0]
    unless err
      @setState nextState.title
    else
      warn err.msg or "there was an error, couldn't switch to #{nextState} state!"<commit_msg>KDToggleButton: Seperate internal calls and user calls for setState<commit_after>class KDToggleButton extends KDButtonView

  constructor:(options = {}, data)->

    options = $.extend
      dataPath     : null          # a JsPath String
      defaultState : null          # a String
      states       : []            # an Array of Objects in form of stateName : callback key/value pairs
    , options

    super options, data

    @setState options.defaultState, no

  getStateIndex:(name)->

    {states} = @getOptions()
    unless name
      return 0
    else
      for state, index in states
        if name is state.title
          return index

  decorateState:(name, userEvent)->
    @setTitle @state.title
    @setIconClass @state.iconClass if @state.iconClass?

  getState:-> @state

  setState:(name, userEvent = yes)->

    {states} = @getOptions()
    @stateIndex = index = @getStateIndex name
    @state      = states[index]
    @decorateState name, userEvent

    @setCallback states[index].callback.bind @, @toggleState.bind @

  toggleState:(err)->

    {states} = @getOptions()
    nextState = states[@stateIndex + 1] or states[0]
    unless err
      @setState nextState.title
    else
      warn err.msg or "there was an error, couldn't switch to #{nextState} state!"
    @hideLoader?()
{'fraction_non_alphanumeric': 0.09935897435897435, 'fraction_numerical': 0.002403846153846154, 'mean_word_length': 2.546875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4319433', 'n_tokens_mistral': 738, 'n_tokens_neox': 694, 'n_words': 217}