/** @babel */
/** global atom */

import { delay } from 'redux-saga'
import { put, call, select, take, fork } from 'redux-saga/effects'
import { run } from 'node-jq'
import { ACTIONS as ACTION } from './constants'

const ONE_SEC = 1000

// const jq = (filter) => {
//   return (dispatch, getState) => {
//     const { activePaneItem } = getState()
//     return run(filter, activePaneItem.getText(), { input: 'string' }).then(
//       output => dispatch(jqFilterSuccess(output)),
//       error => dispatch(jqFilterFailure(error))
//      )
//   }
// }

function * jq () {
  while (true) {
    const action = yield take(ACTION.JQ_FILTER_REQUEST)
    const activePaneItem = yield select(state => state.activePaneItem)
    const { payload: { filter } } = action
    const filePath = activePaneItem.buffer.file.path
    try {
      const result = yield run(filter, filePath)
      yield call(ACTION.OPEN_MODAL, result)
    } catch (e) {
      yield call(ACTION.JQ_FILTER_FAILURE)
    }
    yield call(delay, ONE_SEC)
  }
}

export default function * sagas () {
  yield [
    fork(jq)
  ]
}

@@ -234,326 +234,8 @@
 00%0A%0A
-// const jq = (filter) =%3E %7B%0A//   return (dispatch, getState) =%3E %7B%0A//     const %7B activePaneItem %7D = getState()%0A//     return run(filter, activePaneItem.getText(), %7B input: 'string' %7D).then(%0A//       output =%3E dispatch(jqFilterSuccess(output)),%0A//       error =%3E dispatch(jqFilterFailure(error))%0A//      )%0A//   %7D%0A// %7D%0A%0A
 func

Remove commented thunk code in saga