import {setScrollBehaviour, setSearchFormCollapsed} from './modules/list/actions'

const isDefined = value => value !== undefined

export const getDispatchActions = input =>
  actionSettings.reduce((acc, actionSetting) => {
    if (isDefined(input[actionSetting.name])) {
      acc.push(actionSetting.action(...actionSetting.argsFactory(input)))
    }
    return acc
  }, [])

const actionSettings = [
  {
    name: 'searchFormCollapsed',
    action: setSearchFormCollapsed,
    argsFactory: input => [input.searchFormCollapsed]
  },
  {
    name: 'scrollBehaviour',
    action: setScrollBehaviour,
    argsFactory: input => [input.scrollBehaviour]
  }
]

import {action} from 'tocco-util'

import {setScrollBehaviour, setSearchFormCollapsed} from './modules/list/actions'

export const getDispatchActions = input => action.getDispatchActions(input, actionSettings)

const actionSettings = [
  {
    name: 'searchFormCollapsed',
    action: setSearchFormCollapsed,
    argsFactory: input => [input.searchFormCollapsed]
  },
  {
    name: 'scrollBehaviour',
    action: setScrollBehaviour,
    argsFactory: input => [input.scrollBehaviour]
  }
]

refactor dispatch actions