-
-
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
add default export #494
add default export #494
Conversation
LGTM |
Should we document this as well? You too often have to guess how to |
@zixia Mind adding something to the README? |
@ralphtheninja Ok, I will try to add some docs for this. |
I just add some docs about to introduce the Do not know where is the best position to add them, so I put them after the |
I feel this could be simpler, what about having this in the first code example: var levelup = require('levelup')
var leveldown = require('leveldown')
// or
import levelup from 'levelup'
import leveldown from 'leveldown' |
@juliangruber No problem for me. I can modify the PR if needed. Actually, this PR does not change any import/require usage than before. It only affects the |
Well, it adds the ability to import the default export for any es6 modules compliant environment. |
README.md
Outdated
|
||
We have two ways to import(require) the levelup module in the code. | ||
|
||
### 1. The old fashioned `require` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using require
README.md
Outdated
var levelup = require('levelup') | ||
``` | ||
|
||
### 2. The new ES6 `import` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using ES6 import
README.md
Outdated
import levelup from 'levelup' | ||
``` | ||
|
||
## TypeScript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove this section? Not sure what it has to do with this PR? (And we did remove typings for now until a later version)
Edited by following reviews from @ralphtheninja |
I think typescript will have a hard time supporting both with this because you're mixing module kinds: export = levelup;
export default levelup; error:
So to type this I'd have to pick one kind for ts users. Currently, ts users have: import * as levelup from 'levelup'; switching over to the default export would mean ts-users would need to do: import levelup from 'levelup'; This does work for me locally and moving forward, using the es6 standard appears to make sense. I would caution though that the way es6 module loaders deal with es6 modules is not the same as commonjs: which is why nodejs still isn't switching over: https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-node-js-42c958b890c |
@MeirionHughes Yes, you can not use We should either to use
export { levelup }
export default levelup or
export = levelup.default = levelup.levelup = levelup I believe in both of above two kinds, the user could always use |
It has to stay const levelup = require('levelup') for "older" systems though, is there a way to keep this and make es6 environments happy? |
I'm good with the changes and agree with @juliangruber, whatever you want to pick for es6 stuff should not mess up current functionality. |
@juliangruber Yes, I agree with you that we have to stay This PR did not affect the "older" systems usage because it only adds a |
When will we publish the latest version to NPM? Thanks! |
I've got the typings nearly ready to add back in to; waiting on leveldown. |
Enable us to use
import levelup from 'levelup'
by addingdefault
export.