Level / abstract-leveldown

An abstract prototype matching the leveldown API.
MIT License
146 stars 53 forks source link

Consider defining default methods on prototype #193

Closed vweevers closed 6 years ago

vweevers commented 6 years ago

To make TypeScript stop complaining about undefined types, instead of:

AbstractChainedBatch.prototype.put = function (key, value) {
  // ..

  // @ts-ignore
  if (typeof this._put === 'function') {
    // @ts-ignore
    this._put(key, value)
  } else {
    this._operations.push({ type: 'put', key: key, value: value })
  }

  // ..
}

We could write:

AbstractChainedBatch.prototype.put = function (key, value) {
  // ..

  this._put(key, value)

  // ..
}

AbstractChainedBatch.prototype._put = function (key, value) {
  this._operations.push({ type: 'put', key: key, value: value })
}

Same with all the other methods. Thoughts @ralphtheninja @juliangruber?

vweevers commented 6 years ago

@ralphtheninja such a change could be a patch release, right? It doesn't change behavior, unless someone is doing some funky prototype stuff (I wouldn't know what).

ralphtheninja commented 6 years ago

Aye, a patch version should be sufficient.

vweevers commented 6 years ago

We have a weird one here:

https://github.com/Level/abstract-leveldown/blob/0d942fd45df5c9915269ded6f0f76fdfade11575/abstract-chained-batch.js#L79-L85

Notice that _write doesn't receive options.