docs: function put (state, doc) {
    return new Promise(function (resolve, reject) {
      var scope = {
        wantedRev: null,
        missedChangedDocs: [],
        resolve: resolve
      }
  
      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.putPromise = state.db.put(doc)
  
      .then(function (result) {
        doc._id = result.id
        doc._rev = result.rev
        scope.result = doc
        scope.wantedRev = result.rev
        scope.missedChangedDocs.forEach(scope.changeHandler.bind(null, state, scope, null))
      })
  
      .catch(reject)
    })
  }