docs: function addMiddleware (state, stack, spec, name) {
    if (_.isFunction(spec)) {
      stack.append(spec, spec.name || name)
    } else if (_.isString(spec)) {
      const middleware = findMiddleware(state, spec)
      if (middleware.calls) {
        stack.appendStack(middleware)
      } else {
        stack.append(middleware.call, middleware.name)
      }
    } else if (Array.isArray(spec)) {
      if (spec.length) {
        if (spec[ 0 ].when && spec[ 0 ].then) {
          stack.append(spec, name)
        } else {
          _.each(spec, function (item, index) {
            addMiddleware(state, stack, item, [ name, index ].join('-'))
          })
        }
      }
    } else if (_.isObject(spec)) {
      stack.appendStack(spec)
    }
  }