-
Notifications
You must be signed in to change notification settings - Fork 492
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
[IFI-419] Remove redundant export from generator-metal-clay template #1453
Conversation
I asked about the convention of doing a double export: ```javascript export Thing; export default Thing; ``` here: #1440 (comment) I just wanted to throw up this PR to have something concrete to use as a basis for discussion about potentially moving away from this pattern. I think it would be desirable in the interests of being "conventional" (down with innovation! viva la convention!). We'd need to do 2 or potential 3 steps to make this happen: 1. (This PR) Make the generator produce only the default export. 2. In the existing packages, consider emitting a deprecation warning if people use the non-default export. 3. In a future major semver release, remove the non-default exports. Step 2 there is optional, but would consist of some (potentially tricky) wrapping/subclassing of the exported class that would produce a once-only `console.warn` in the constructor. Related: https://issues.liferay.com/browse/IFI-419
Just read this article yesterday, thought it might be good food-for-thought in regards to this conversation. https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/ |
@bryceosterhaus: Yeah, I saw that too. I think most of his confusion stems from the fact that the files he's importing from are not named after the thing that is their default export, but it should be. That is, if the file exports a |
Hey @bryceosterhaus, @wincent, I think we tried to standardize around both exports because initially we had plenty some modules doing both, exporting defaults and named and consumers where importing them either way too...
I think this was early days, as you can see from metal-dom/dom.js and metal-dom/domNamed.js In I can't remember another reason why we decided to do this dual export, so I'd be fine to revert this decision and follow a deprecation plan like @wincent proposed. |
LGTM! I do not see any problem in following this, I like the idea of following the depreciation plan, I think it's important to issue the warnings so people can prepare. |
I also remember asking this question a while ago. As far as I'm concerned, I've read a couple of articles/threads regarding default exports vs named exports: https://blog.neufund.org/why-we-have-banned-default-exports-and-you-should-do-the-same-d51fdc2cf2ad I prefer named exports, but that's just a personal preference |
@julien: There are some pretty good arguments against default exports in those links. I think there are a few positions that we could adopt: 1. Never use default exports.
2. Use default exports whenever you feel like
The main other disadvantage I see is brittleness in the face of refactoring: if somebody changes which export is the default (a terrible idea) you rely on your type system, tests, or manual verification to catch the issue; if somebody changes the name of the module or the default export, there is no built-in enforcement that obliges you to update the importing code as well. 3. Use default exports only in the simple case where a module is exporting a single thing.
Having written a lot of CommonJS, it was pretty natural for me to use style "2" or "3" because that is what seemed to map most closely to the CommonJS way of being able to immediately use the export of a module that only had a single export, but I think a pretty good case can be made for "1" because it is the most fool-proof approach. |
LGTM! |
LGTM, can't remember any particular reason to do this. Anyway, if we change it in the generator shouldn't we update all the components to follow this rule and keep consistency? Thx @wincent ! |
Yes, @carloslancha, I think that's right. As I said in my original post, that would be a breaking change though, so probably want to do it in three steps (change generator; issue deprecation warnings; actual remove in a semver-major release). |
hey guys, as we all agree, I think we can merge this and create an issue so we can track the progress of the steps of adding the warnings and we can start removing it from the next version v3.x. |
I created issue #1495, to go ahead with it and merge into the |
@matuzalemsteles @wincent remember to use convention for the commit messages please. |
hey @carloslancha, Sorry about that 😅. |
Sorry about that @carloslancha. I wrote this one 14 days ago, before I knew about the convention. |
I asked about the convention of doing a double export:
here:
#1440 (comment)
I just wanted to throw up this PR to have something concrete to use as a basis for discussion about potentially moving away from this pattern. I think it would be desirable in the interests of being "conventional" (down with innovation! viva la convention!).
We'd need to do 2 or potential 3 steps to make this happen:
Step 2 there is optional, but would consist of some (potentially tricky) wrapping/subclassing of the exported class that would produce a once-only
console.warn
in the constructor.Related: https://issues.liferay.com/browse/IFI-419