Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

chore: export constants from index #4593

Merged
merged 18 commits into from
May 15, 2019
Merged

Conversation

moog16
Copy link
Contributor

@moog16 moog16 commented Apr 11, 2019

fixes #4579

@moog16 moog16 changed the title fix: export constants from index chore: export constants from index Apr 11, 2019
@mdc-web-bot
Copy link
Collaborator

All 636 screenshot tests passed for commit cc2224c vs. master! 💯🎉

Matt Goo added 2 commits April 11, 2019 16:17
@mdc-web-bot
Copy link
Collaborator

All 636 screenshot tests passed for commit 3f70c99 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 636 screenshot tests passed for commit 3dedadd vs. master! 💯🎉

@@ -23,4 +23,8 @@

export * from './adapter';
export * from './component';
export {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea would be for all of them do something like: export * as chipSetConstants from './constants';. That way you don't have to rename all the individual symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I like that idea...I"ll try that out :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that syntax actually works.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting looks like you're right. I assumed it would since that style syntax works for import. In that case I think you could accomplish the same thing like this:

import * as chipSetConstants from './constants';
export {chipSetConstants};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - I did try that but I forgot the *...Not as clean as your original, but better than manually naming everything.

@@ -23,5 +23,9 @@

export * from './adapter';
export * from './component';
export {
strings as tabBartrings,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabBarStrings

Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, we could also solve another problem for CDN users & consumers who directly consume dist/ build.

Problem

Since we're not exporting constants (cssClasses, strings, etc.) consumers have to rely on foundation static methods (e.g., MDCFooFoundation.cssClasses) to access these constants. This is additional cost of bundle size and maintenance.

Proposal

Every constant file will have a default export with namespace prefix and named exports (for backward compatibility).

export {cssClasses, strings, numbers, CornerBit, Corner};
const MDCMenuSurfaceConstants = {cssClasses, strings, numbers, CornerBit, Corner};
export default MDCMenuSurfaceConstants;

Usage:

import MDCMenuSurfaceConstants from './constants';
const {cssClasses, strings} = MDCMenuSurfaceConstants;

This will also avoid variable name clashing when exporting multiple cssClasses from different components.

Usage with UMD Module:

mdc.menuSurface.MDCMenuSurfaceConstants.cssClasses;

@moog16
Copy link
Contributor Author

moog16 commented Apr 18, 2019

With this change as is, you should already be able to do something like:

mdc.menuSurface.cssClasses;

Is that what you were proposing?

@mdc-web-bot
Copy link
Collaborator

All 636 screenshot tests passed for commit ff92450 vs. master! 💯🎉

Matt Goo added 2 commits April 18, 2019 17:23
…mponents/material-components-web into chore/export-constants-index
@mdc-web-bot
Copy link
Collaborator

All 636 screenshot tests passed for commit c5a18c8 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 639 screenshot tests passed for commit 1dba3a2 vs. master! 💯🎉

@codecov-io
Copy link

codecov-io commented May 2, 2019

Codecov Report

Merging #4593 into master will decrease coverage by 0.29%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #4593     +/-   ##
=========================================
- Coverage   99.26%   98.97%   -0.3%     
=========================================
  Files         129      129             
  Lines        6294     6329     +35     
  Branches      821      821             
=========================================
+ Hits         6248     6264     +16     
- Misses         45       64     +19     
  Partials        1        1
Impacted Files Coverage Δ
packages/mdc-menu/index.ts 100% <100%> (ø) ⬆️
packages/mdc-tab/index.ts 100% <100%> (ø) ⬆️
packages/mdc-tabs/tab/index.ts 100% <100%> (ø) ⬆️
packages/mdc-grid-list/index.ts 100% <100%> (ø) ⬆️
packages/mdc-switch/index.ts 100% <100%> (ø) ⬆️
packages/mdc-list/index.ts 100% <100%> (ø) ⬆️
packages/mdc-textfield/icon/index.ts 100% <100%> (ø) ⬆️
packages/mdc-line-ripple/index.ts 100% <100%> (ø) ⬆️
packages/mdc-select/icon/index.ts 100% <100%> (ø) ⬆️
packages/mdc-ripple/index.ts 100% <100%> (ø) ⬆️
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7940370...bbe16e8. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

All 642 screenshot tests passed for commit bb3f76e vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 645 screenshot tests passed for commit a2d7013 vs. master! 💯🎉

@moog16
Copy link
Contributor Author

moog16 commented May 8, 2019

We've decided to go the route of exporting all constants as cssClasses or strings, etc. unless it comes from within a subcomponent (ie. chips, chipSet). These will be prepended with the subcomponent name: chipCssClasses or chipSetCssClasses.

Matt Goo added 2 commits May 8, 2019 13:59
This reverts commit 70be8b3.
@mdc-web-bot
Copy link
Collaborator

All 645 screenshot tests passed for commit 16060ff vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 645 screenshot tests passed for commit 2641482 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 645 screenshot tests passed for commit 6857c65 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 645 screenshot tests passed for commit 408f681 vs. master! 💯🎉

Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one comment.

Since this is a breaking change, rebase your changes to develop branch.

packages/mdc-select/index.ts Outdated Show resolved Hide resolved
export * from './adapter';
export * from './component';
export * from './foundation';
export {chipSetCssClasses, chipSetStrings};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly export without additional import statement.

export {cssClasses as chipSetCssClasses, strings as chipSetStrings} from './constants';

@abhiomkar
Copy link
Collaborator

Also, Add BREAKING CHANGE: line to PR description.

@moog16
Copy link
Contributor Author

moog16 commented May 15, 2019

I dont think this is a breaking change. This is a new feature, so its not going to break anyone currently using our components.

@mdc-web-bot
Copy link
Collaborator

All 687 screenshot tests passed for commit e9016ec vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 687 screenshot tests passed for commit bbe16e8 vs. master! 💯🎉

@moog16 moog16 merged commit 5064fda into master May 15, 2019
@moog16 moog16 deleted the chore/export-constants-index branch May 15, 2019 22:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All packages /index should export ./constants
6 participants