Skip to content
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

Switch to classes and ES6/esmodule TS compilation #62

Conversation

taylorthurlow
Copy link
Contributor

I'm not 100% sure if this PR is welcome - this is obviously a big rewrite/refactor of how this is all structured, and will break every existing app that uses this library. So, no hard feelings if this gets closed, I mostly did this because I'm using this in a web app, and the size of the gzipped bundle when this library is included is WAY too high (2.6mb gzipped).

This is a rewrite which moves the primary Country, State, and City interfaces into their own classes. Each class has appropriate class and instance methods which replicate the existing functionality of the library, but in a way which allows full tree-shaking when one or more classes are not used in the dependent application.

In order to support tree-shaking, I had to change the TypeScript compiler options to generate ES6 compatible modules rather than CommonJS modules, and I'm not really an expert on JS in general, so I don't know what the implications are of that change as far as compatibility. I know that this should be fine for web applications, and I believe newer versions of Node will be fine with ES modules.

I'm still playing around with this, and I haven't updated the tests yet, so I'm marking this as a draft. Let me know if there is any interest in merging this.

Thanks!

@harpreetkhalsagtbit
Copy link
Owner

@taylorthurlow Thanks for your effort. Your concerns are right but I hope it won't go waste.

@harpreetkhalsagtbit harpreetkhalsagtbit self-assigned this Jun 10, 2021
@harpreetkhalsagtbit harpreetkhalsagtbit changed the base branch from master to feature/refactoring-new-typescript-classes June 10, 2021 06:57
@harpreetkhalsagtbit
Copy link
Owner

@taylorthurlow updated the base branch - I will review and test it further.

@taylorthurlow taylorthurlow marked this pull request as ready for review June 11, 2021 19:00
@taylorthurlow
Copy link
Contributor Author

Thanks for taking a look! I just rewrote the tests and pushed everything up. I have 100% coverage but there is some weirdness with the branch coverage percentage on src/city.ts, which I can't figure out.

@harpreetkhalsagtbit harpreetkhalsagtbit changed the base branch from feature/refactoring-new-typescript-classes to develop June 19, 2021 14:00
@harpreetkhalsagtbit
Copy link
Owner

@taylorthurlow your code is already refactored and merged into the develop branch.

@taylorthurlow
Copy link
Contributor Author

@taylorthurlow your code is already refactored and merged into the develop branch.

Thanks! Sorry I've been busy. Will get to this sometime next week I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants