<commit_before>import { observable, extendObservable } from 'mobx'
import keyMapConfig, { modifierKeysMap } from 'commands/keymaps'

const findKeyByValue = value => Object
    .keys(keyMapConfig)
    .reduce((p, v) => {
      p[keyMapConfig[v]] = v
      return p
    }, {})[value] || ''

const withModifierKeys = value => value.split('+')
    .map(e => modifierKeysMap[e] || e.toUpperCase()).join('')


function MenuScope (defaultMenuItems=[]) {

  class MenuItem {
    constructor (props) {
      let subItems
      if (Array.isArray(props.items)) {
        subItems = props.items.map(itemProps => new MenuItem(itemProps))
        delete props.items
      }
      extendObservable(this, props)

      if (subItems) extendObservable(this, { items: subItems })
      if (this.command) {
        extendObservable(this, {
          get shortcut () {
            return withModifierKeys(findKeyByValue(this.command))
          }
        })
      }
      return this
    }
  }

  const state = observable({
    items: defaultMenuItems.map(props => new MenuItem(props)),
  })

  return { state, MenuItem }
}

export default MenuScope<commit_msg>Revert ":bug: fix bug in 'commons/Menu/state'"<commit_after>import React from 'react'
import { observable, extendShallowObservable } from 'mobx'
import keyMapConfig, { modifierKeysMap } from 'commands/keymaps'

const findKeyByValue = value => Object
    .keys(keyMapConfig)
    .reduce((p, v) => {
      p[keyMapConfig[v]] = v
      return p
    }, {})[value] || ''

const withModifierKeys = value => value.split('+')
    .map(e => modifierKeysMap[e] || e.toUpperCase()).join('')


function MenuScope (defaultMenuItems=[]) {

  class MenuItem {
    constructor (opts) {
      const keys = Object.keys(opts)
      keys.forEach((keyName) => {
        switch (keyName) {
          case 'items':
            const subItems = opts.items.map(itemOpts => new MenuItem(itemOpts))
            return extendShallowObservable(this, {
              items: subItems,
              get itemsMap () {
                return this.items.reduce((acc, item) => {
                  if (item.key) acc[item.key] = item
                }, {})
              },
              get shortcut () {
                return withModifierKeys(findKeyByValue(this.command))
              }
            })
          // case 'key':
          // case 'name':
          // case 'className':
          // case 'command':
          // case 'isDisabled':
          default:
            return extendShallowObservable(this, { [keyName]: opts[keyName] })
        }
      })
      return this
    }
  }

  const state = observable({
    items: observable.shallowArray(defaultMenuItems.map(opts => new MenuItem(opts))),
    get itemsMap () {
      return this.items.reduce((acc, item) => {
        if (item.key) acc[item.key] = item
      }, {})
    }
  })

  return { state, MenuItem }
}

export default MenuScope
{'fraction_non_alphanumeric': 0.13514442916093536, 'fraction_numerical': 0.0, 'mean_word_length': 2.2648709315375983, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 18, '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': '781093', 'n_tokens_mistral': 873, 'n_tokens_neox': 859, 'n_words': 188}