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

Refactor/core #59

Merged
merged 62 commits into from Dec 16, 2016
Merged

Refactor/core #59

merged 62 commits into from Dec 16, 2016

Conversation

vigreco
Copy link
Collaborator

@vigreco vigreco commented Nov 22, 2016

This is the first part of the refactor proposed in #56.
It is focused on lib structure and reorganization of core files.

The initial qrcode.js file has been splitted in many separated modules to make code easier to follow and update.
Some parts have been reimplemented and where possible some optimisations have been added to make the qrcode generation faster.
Also, I tried to comment and document as much as possible the code to explain what it does.

For each core module has been added an initial test file which cover the implementation.
More tests should be added in future to cover possible edge cases.

Example files have been moved to a dedicated folder and all files not needed have been excluded from publishing to have a cleaner package.

Code has been refactored and commented to be easier to follow.
All datas and functions related to error correction have been moved to a dedicated file.
EC blocks and EC codewords values, have been splitted into two tables for better handling.

Methods inside Polynomial class have been rewrited as static functions since are just used like maths utility methods.
`Polynomial.mod` has been refactored to avoid recursive calls.

EC generation is now handled by `ReedSolomonEncoder` class.
Code has been optimized to create a generator polynomial just once instead of re-calculate it at each iteration.

Arrays and `bops` lib have been replaced with Buffer.
Browserify and Webpack shims for node Buffer include a lot of methods that will be likely never used by this lib.
This commit add a stripped version of the original Buffer shim, with only the methods strictly needed.

Bundle size is reduced by ~50%, resulting in a footprint of only ~7Kb (minified and gzipped).
@soldair
Copy link
Owner

soldair commented Nov 22, 2016

wow! ill take a look now

@soldair
Copy link
Owner

soldair commented Nov 22, 2016

one issue is that prepublish runs on npm install also. this means that folks have to run the tests just to install it as a dep

also we build the browser version before we publish so that folks dont have to when they install and they dont need the dev deps like browserify

im not sure if i left these wires crossed before you got to it (probably) but lets figure out how to solve it before this release

@vigreco
Copy link
Collaborator Author

vigreco commented Nov 22, 2016

It makes sense. I'll remove the test task from prepublish.
However, if the package is installed as a dep, prepublish shouldn't be executed, or am I wrong?

@vigreco
Copy link
Collaborator Author

vigreco commented Nov 26, 2016

I've just noticed there was a bug in encode method that would occur using numeric or alphanumeric mode. Probably also in some rare cases in byte mode. Fixed now.

(num and alphanum modes are not implemented yet, I'm working on them in another branch, I hope to push it soon)

@soldair
Copy link
Owner

soldair commented Nov 28, 2016

this is amazing work. i just wanted to say thanks! and im glad you are digging in

@vigreco
Copy link
Collaborator Author

vigreco commented Nov 28, 2016

it's a pleasure 😄
Let me know if there is something else you want me to change 👍

@soldair
Copy link
Owner

soldair commented Dec 12, 2016

if you think this is ready to go i approve. please go ahead and merge.

@vigreco
Copy link
Collaborator Author

vigreco commented Dec 15, 2016

@soldair I've added a few changes. If it's still ok for you I'm ready to merge this.

@soldair
Copy link
Owner

soldair commented Dec 15, 2016

hmm. if anyone is using the build path in their scripts that require this libraray their scripts will be broken.
we'll have to release this in a semver major change. with all of these changes we may already have to.
did we change the api/arguments in any other non backwards compatible way?

@vigreco
Copy link
Collaborator Author

vigreco commented Dec 15, 2016

mm ok, you've right, I hadn't thought of that. I probably have to revert it to the old name for now.

I've intentionally kept all the API untouched for this first part of the refactor.
All the changes affect only the internal code.
I'll introduce some changes and some new API in the refactor of the rendering part, I think.
Anyway should not be a problem keep also the current interface for backward compatibility.

The only thing that I've removed is one of the global var exported for the browser.
Now there's only window.qrcodelib (window.QRCodeLib has been removed) since the readme was covering only the former, here.

A rough roadmap for the next changes could be:

  • 0.6.0: core refactor
  • 0.7.0: add support for Numeric and Alphanumeric mode (with auto select of best mode)
  • 0.8.0: renderer refactor
  • 0.9.0: add support for other output formats (jpg, pdf, css, table, ascii, ...)
  • 1.0.0: initial support for image effects (logo, shadow, rounded modules, ...)

@soldair
Copy link
Owner

soldair commented Dec 16, 2016

awesome 👍

@soldair
Copy link
Owner

soldair commented Dec 16, 2016

🐑

@vigreco vigreco merged commit 77064f5 into master Dec 16, 2016
@soldair
Copy link
Owner

soldair commented Dec 17, 2016

👏 🎊

@vigreco vigreco deleted the refactor/core branch October 25, 2017 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants