docs: function bulkDocs (state, docs) {
    return new Promise(function (resolve, reject) {
      var scope = {
        wantedRevs: [],
        missedChangedDocs: [],
        resolve: resolve,
        result: [],
        docs: docs
      }
  
      scope.changeHandler = changeHandler.bind(null, state, scope)
      scope.resetHandler = resetHandler.bind(null, state, scope)
      state.emitter.on('change', scope.changeHandler)
      state.emitter.once('reset', scope.resetHandler)
  
      scope.bulkDocsPromise = state.db.bulkDocs(docs)
  
      .then(function (result) {
        if (result.length === 0) {
          state.emitter.removeListener('change', scope.changeHandler)
          state.emitter.removeListener('reset', scope.resetHandler)
          resolve([])
          return
        }
  
        scope.result = result
          .map(internals.toNormalisedError.bind(null, scope))
          .map(function (result, i) {
            if (!result.rev) {
              return result
            }
  
            docs[i]._id = result.id
            docs[i]._rev = result.rev
            return docs[i]
          })
        scope.wantedRevs = result.map(toRev).filter(Boolean)
      })
  
      .catch(reject)
    })
  }