-
-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optional location & options arguments #208
Conversation
+1 |
Why a factory and not just an instance? |
@mmalecki because you can close and open a database. It even says in the readme that reopening a database is not adviced, so I'm inclined to drop that feature and pass in an instance here, way cleaner. |
+1 for instance |
so, when this is a leveldown instance, should it be preopened? |
if it's not a factory then it'd need separate options for setting up the instance and setting up levelup var db = levelup({ valueEncoding: 'json' }, leveldown({ createIfMissing: false })) too messy IMO, I'm keen to stick with the factory. Letting LevelUP manage instantiation gives it a chance to properly manage state for deferred-open operations, it knows exactly what state it's up to, it can use the callback to leveldown to trigger a completion to the open. +1 to keeping factory, -1 to passing in an instance |
an instance could be okay, if you have already opened the instance. |
After reconsidering the open case, I'm +1 on factory. PR LGTM. |
+1 for merging in, then |
optional location & options arguments
ref #206 as per @mmalecki's suggestion
This gives two new constructor forms: levelup(options[, callback ]) and levelup(db[, callback ]).
If you don't provide a
location
argument but do provide an'object'
as your first argument then it must have a'db'
property that's a'function'
which is assumed to be a backend factory; otherwise it fails. The second form is where you don't provide alocation
argument but you do provide a'function'
as your first argument, this is assumed to be a back-end factory. In both cases a second argument is allowable, a callback'function'
but this is optional. We can't do a form where you provide alocation
as the first argument and a back-end factory as the second because we can't tell if it's supposed to be a factory or a callback, unless you provide a callback as well, but then, you're getting verbose anyway so it's just silly.required new DeferredLevelDOWN and MemDOWN releases to make the
location
optional.