Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Consider defining default methods on prototype #193

Closed
vweevers opened this issue Jan 22, 2018 · 3 comments
Closed

Consider defining default methods on prototype #193

vweevers opened this issue Jan 22, 2018 · 3 comments
Assignees
Labels
question Support or open question(s)

Comments

@vweevers
Copy link
Member

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 vweevers added the question Support or open question(s) label Jan 22, 2018
@vweevers
Copy link
Member Author

@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
Copy link
Member

Aye, a patch version should be sufficient.

@vweevers
Copy link
Member Author

We have a weird one here:

if (typeof this._write === 'function') { return this._write(callback) }
if (typeof this._db._batch === 'function') {
return this._db._batch(this._operations, options, callback)
}
process.nextTick(callback)

Notice that _write doesn't receive options.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Support or open question(s)
Projects
None yet
Development

No branches or pull requests

2 participants