Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
import { ReactNode } from 'react'
import { fromMapToArray } from 'exotic'
import { action, decorate, observable } from 'xmobx/mobx'
import { ISidebarGroup, SidebarItemMapper } from './typings'
import { SidebarItemState } from '../SidebarItem'

export class SidebarGroupState implements ISidebarGroup {
  private store = observable.map()

  /**
   * @alias addSidebar
   * @chainable
   */
  @action
  add(item: SidebarItemState) {
    this.store.set(item.identifier, item)
    return this
  }

  /**
   * @description remove all sidebars
   * @chainable
   */
  @action
  clear() {
    this.store.clear()
    return this
  }

  /**
   * @description iterate over all sidebars
   */
  map(handler: SidebarItemMapper) {
    const iteratee = (pair, index) => {
      const [key, value] = pair
      return handler(value, index)
    }
    return fromMapToArray(this.store).map(iteratee)
  }
}