<commit_before>/* @flow */

import * as atoms from './atom-streams'
import {Directory} from 'atom'
import Bacon from 'baconjs'
import classNames from 'classnames'
import fs from 'fs-plus'
import Path from 'path'
import R from 'ramda'
import {React, ReactDOM} from 'react-for-atom'
import LoadingProgress from './react/loading-progress'
import Search from './react/search'
import TableColumnsHeader from './react/table-columns-header'
import ScrollableList from './react/scrollable-list'
import Cell from './react/cell'
import EditCellStr from './react/edit-cell-str'
import ResizeHandle from './react/resize-handle'

const DOUBLE_CLICK_THROTTLE_TIME = 300 // ms

export default class ViewCtrl {

  abortEditCellS: Bacon.Stream
  activePathS: Bacon.Stream
  clickedCellS: Bacon.Stream
  dblClickedCellS: Bacon.Stream
  keyDownS: Bacon.Stream
  keyEnterS: Bacon.Stream
  keyEscS: Bacon.Stream
  keyUpS: Bacon.Stream
  listHeightS: Bacon.Stream
  rowHeightS: Bacon.Stream
  saveEditedCellContentS: Bacon.Stream
  scrollTopS: Bacon.Stream
  sessionStartS: Bacon.Stream
  sortDirectionS: Bacon.Stream
  sortFieldS: Bacon.Stream
  textInputS: Bacon.Stream

  _panel: Atom$Panel
  _abortEditCellBus: Bacon.Bus
  _clickCellBus: Bacon.Bus
  _keyDownBus: Bacon.Bus
  _listHeightBus: Bacon.Bus
  _saveEditedCellContentBus: Bacon.Bus
  _scrollTopBus: Bacon.Bus
  _selectedIndexBus: Bacon.Bus
  _sortDirectionBus: Bacon.Bus
  _sortFieldBus: Bacon.Bus
  _startSessionBus: Bacon.Bus
  _textInputBus: Bacon.Bus

  constructor (panel: Atom$Panel) {
    this._panel = panel

    this._abortEditCellBus = new Bacon.Bus()
    this._clickCellBus = new Bacon.Bus()
    this._keyDownBus = new Bacon.Bus()
    this._listHeightBus = new Bacon.Bus()
    this._saveEditedCellContentBus = new Bacon.Bus()
    this._scrollTopBus = new Bacon.Bus()
    this._selectedIndexBus = new Bacon.Bus()
    this._sortDirectionBus = new Bacon.Bus()
    this._sortFieldBus = new Bacon.Bus()
    this._startSessionBus = new Bacon.Bus()
    this._textInputBus = new Bacon.Bus()

    this.abortEditCellS = this._abortEditCellBus
    this.rowHeightS = atoms.createConfigStream('textual-velocity.rowHeight').skipDuplicates()
    this.saveEditedCellContentS = this._saveEditedCellContentBus
    this.scrollTopS = this._scrollTopBus
    this.sessionStartS = this._startSessionBus
    this.textInputS = this._textInputBus

    this.activePathS = atoms
      .createStream(atom.workspace, 'onDidStopChangingActivePaneItem')
      .map(paneItem => {
        if (paneItem && paneItem.getBuffer) {
          const buffer = paneItem.getBuffer()
          if (buffer) return buffer.getPath()
        }
      })
      .skip(1)

    this.dblClickedCellS = this._clickCellBus
      .bufferWithTimeOrCount(DOUBLE_CLICK_THROTTLE_TIME, 2)
      .flatMap(([a, b]) => {
        return b && b.cell || Bacon.never()
      })

    this.clickedCellS = this._clickCellBus // single click
      .map(({filename}) => ({
        time: +new Date(),
        filename: filename}))
      .toProperty({time: 0})
      .slidingWindow(2, 2)
      .flatMap(([a, b]) => {
        return b.time - a.time > DOUBLE_CLICK_THROTTLE_TIME
          ? b.filename
          : Bacon.never()
      })

    const newKeyS = keyCode => this._keyDownBus
      .filter(R.propEq('keyCode', keyCode))
      .doAction('.preventDefault')
    this.keyDownS = newKeyS(40)
    this.keyEnterS = newKeyS(13)
    this.keyEscS = newKeyS(27)
    this.keyUpS = newKeyS(38)

    this.listHeightS = Bacon
      .mergeAll(
        this._listHeightBus,
        atoms.createConfigStream('textual-velocity.listHeight'))
      .skipDuplicates()

    this.sortDirectionS = Bacon
      .mergeAll(
        this._sortDirectionBus,
        atoms.createConfigStream('textual-velocity.sortDirection'))
      .skipDuplicates()

    this.sortFieldS = Bacon
      .mergeAll(<commit_msg>:art: Simpler stream conversion<commit_after>/* @flow */

import * as atoms from './atom-streams'
import {Directory} from 'atom'
import Bacon from 'baconjs'
import classNames from 'classnames'
import fs from 'fs-plus'
import Path from 'path'
import R from 'ramda'
import {React, ReactDOM} from 'react-for-atom'
import LoadingProgress from './react/loading-progress'
import Search from './react/search'
import TableColumnsHeader from './react/table-columns-header'
import ScrollableList from './react/scrollable-list'
import Cell from './react/cell'
import EditCellStr from './react/edit-cell-str'
import ResizeHandle from './react/resize-handle'

const DOUBLE_CLICK_THROTTLE_TIME = 300 // ms

export default class ViewCtrl {

  abortEditCellS: Bacon.Stream
  activePathS: Bacon.Stream
  clickedCellS: Bacon.Stream
  dblClickedCellS: Bacon.Stream
  keyDownS: Bacon.Stream
  keyEnterS: Bacon.Stream
  keyEscS: Bacon.Stream
  keyUpS: Bacon.Stream
  listHeightS: Bacon.Stream
  rowHeightS: Bacon.Stream
  saveEditedCellContentS: Bacon.Stream
  scrollTopS: Bacon.Stream
  sessionStartS: Bacon.Stream
  sortDirectionS: Bacon.Stream
  sortFieldS: Bacon.Stream
  textInputS: Bacon.Stream

  _panel: Atom$Panel
  _abortEditCellBus: Bacon.Bus
  _clickCellBus: Bacon.Bus
  _keyDownBus: Bacon.Bus
  _listHeightBus: Bacon.Bus
  _saveEditedCellContentBus: Bacon.Bus
  _scrollTopBus: Bacon.Bus
  _selectedIndexBus: Bacon.Bus
  _sortDirectionBus: Bacon.Bus
  _sortFieldBus: Bacon.Bus
  _startSessionBus: Bacon.Bus
  _textInputBus: Bacon.Bus

  constructor (panel: Atom$Panel) {
    this._panel = panel

    this._abortEditCellBus = new Bacon.Bus()
    this._clickCellBus = new Bacon.Bus()
    this._keyDownBus = new Bacon.Bus()
    this._listHeightBus = new Bacon.Bus()
    this._saveEditedCellContentBus = new Bacon.Bus()
    this._scrollTopBus = new Bacon.Bus()
    this._selectedIndexBus = new Bacon.Bus()
    this._sortDirectionBus = new Bacon.Bus()
    this._sortFieldBus = new Bacon.Bus()
    this._startSessionBus = new Bacon.Bus()
    this._textInputBus = new Bacon.Bus()

    this.abortEditCellS = this._abortEditCellBus
    this.rowHeightS = atoms.createConfigStream('textual-velocity.rowHeight').skipDuplicates()
    this.saveEditedCellContentS = this._saveEditedCellContentBus
    this.scrollTopS = this._scrollTopBus
    this.sessionStartS = this._startSessionBus
    this.textInputS = this._textInputBus

    this.activePathS = atoms
      .createStream(atom.workspace, 'onDidStopChangingActivePaneItem')
      .map(paneItem => {
        if (paneItem && paneItem.getBuffer) {
          const buffer = paneItem.getBuffer()
          if (buffer) return buffer.getPath()
        }
      })
      .skip(1)

    this.dblClickedCellS = this._clickCellBus
      .bufferWithTimeOrCount(DOUBLE_CLICK_THROTTLE_TIME, 2)
      .flatMap(([a, b]) => {
        return b && b.cell || Bacon.never()
      })

    this.clickedCellS = this._clickCellBus // single click
      .map(({filename}) => ({
        time: +new Date(),
        filename: filename}))
      .diff({time: 0}, (a, b) => [a, b])
      .flatMap(([a, b]) => {
        return b.time - a.time > DOUBLE_CLICK_THROTTLE_TIME
          ? b.filename
          : Bacon.never()
      })

    const newKeyS = keyCode => this._keyDownBus
      .filter(R.propEq('keyCode', keyCode))
      .doAction('.preventDefault')
    this.keyDownS = newKeyS(40)
    this.keyEnterS = newKeyS(13)
    this.keyEscS = newKeyS(27)
    this.keyUpS = newKeyS(38)

    this.listHeightS = Bacon
      .mergeAll(
        this._listHeightBus,
        atoms.createConfigStream('textual-velocity.listHeight'))
      .skipDuplicates()

    this.sortDirectionS = Bacon
      .mergeAll(
        this._sortDirectionBus,
        atoms.createConfigStream('textual-velocity.sortDirection'))
      .skipDuplicates()

    this.sortFieldS = Bacon
      .mergeAll(
{'fraction_non_alphanumeric': 0.1091827483486595, 'fraction_numerical': 0.0038855070586711568, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '2046924', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2471, 'n_words': 516}