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

Commit 758cd83

Browse files
committed
Add manifest
1 parent 3243883 commit 758cd83

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

deferred-leveldown.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ var deferrables = 'put get del batch clear'.split(' ')
55
var optionalDeferrables = 'approximateSize compactRange'.split(' ')
66

77
function DeferredLevelDOWN (db) {
8-
AbstractLevelDOWN.call(this, '')
8+
AbstractLevelDOWN.call(this, db.supports || {})
9+
10+
// TODO (future major): remove this fallback; db must have manifest that
11+
// declares approximateSize and compactRange in additionalMethods.
12+
optionalDeferrables.forEach(function (m) {
13+
if (typeof db[m] === 'function' && !this.supports.additionalMethods[m]) {
14+
this.supports.additionalMethods[m] = true
15+
}
16+
}, this)
17+
918
this._db = db
1019
this._operations = []
1120
closed(this)
@@ -51,11 +60,9 @@ function open (self) {
5160
return this._db[m].apply(this._db, arguments)
5261
}
5362
})
54-
optionalDeferrables.forEach(function (m) {
55-
if (typeof self._db[m] === 'function') {
56-
self[m] = function () {
57-
return this._db[m].apply(this._db, arguments)
58-
}
63+
Object.keys(self.supports.additionalMethods).forEach(function (m) {
64+
self[m] = function () {
65+
return this._db[m].apply(this._db, arguments)
5966
}
6067
})
6168
}
@@ -66,11 +73,9 @@ function closed (self) {
6673
this._operations.push({ method: m, args: arguments })
6774
}
6875
})
69-
optionalDeferrables.forEach(function (m) {
70-
if (typeof self._db[m] === 'function') {
71-
self[m] = function () {
72-
this._operations.push({ method: m, args: arguments })
73-
}
76+
Object.keys(self.supports.additionalMethods).forEach(function (m) {
77+
self[m] = function () {
78+
this._operations.push({ method: m, args: arguments })
7479
}
7580
})
7681
self._iterator = function (options) {

0 commit comments

Comments
 (0)