text: import { getKeys } from '../utils/object'
  import { resolveName } from '../services/resolver'
  import Payload from '../classes/Payload'
  
  /**
   * Utility function to grab keys for state
   *
   * @param   {Object|Function|Array|String}   state   State object, state function, array or string of key names
   * @returns {Array}
   */
  function getStateKeys (state) {
    return getKeys(typeof state === 'function' ? state() : state)
  }
  
  /**
   * Helper function to mass-create default getter functions for an existing state object
   *
   * Note that you don't need to create top-level getter functions if using $store.get(...)
   *
   * @param   {Object|Function|Array|String}   state   State object, state function, array or string of key names
   */
  export function makeGetters (state) {
    return getStateKeys(state)
      .reduce(function (obj, key) {
        const getter = resolveName('getters', key)
        obj[getter] = function (state) {
          return state[key]
        }
        return obj
      }, {})
  }
  
  /**
   * Helper function to mass-create default mutation functions for an existing state object
   *
   * @param   {Object|Function|Array|String}   state   State object, state function, array or string of key names
   */
  export function makeMutations (state) {
    return getStateKeys(state)
      .reduce(function (obj, key) {
        const mutation = resolveName('mutations', key)
        obj[mutation] = function (state, value) {
          if (value instanceof Payload) {
            state[key] = value.update(state[key]);
          } else if (typeof value === "object" && "expr" in value && "path" in value && "value" in value) {
            const payload = new Payload (value.expr, value.path, value.value);
            state[key] = payload.update(state[key]);
          } else {
            state[key] = value;
          }
        }
        return obj
      }, {})
  }
  
  /**
   * Helper function to mass-create default actions functions for an existing state object
   *
   * @param   {Object|Function|Array|String}   state   State object, state function, array or string of key names
   */
  export function makeActions (state) {
    return getStateKeys(state)
      .reduce(function (obj, key) {
        const action = resolveName('actions', key)
        const mutation = resolveName('mutations', key)
        obj[action] = function ({commit}, value) {
          commit(mutation, value)
        }
        return obj
      }, {})
  }
  
  export default {
    getters: makeGetters,
    mutations: makeMutations,
    actions: makeActions,
  }
  