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

[WIP] Improved barcode options #171

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

lindell
Copy link
Owner

@lindell lindell commented Jul 4, 2017

This is a WIP of how I want to implement barcode specific options. It does also allow for the awful optionsFromStrings.js to be removed.

It is not done and does not yet work fully, but what do you think of the general idea @SanichKotikov ?

@@ -4,6 +4,10 @@ class Barcode{
this.text = options.text || data;
this.options = options;
}

static options() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you think to make it as a property, but not as a function?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I thought about it. The main reason why I wanted to make this a function is that it will make inheritance of options easier. If for all CODE128 codes have one option but we want to add additional options to that sub-symbology it can easily be done like follow.

static options() {
  return Object.assign({}, super.options(), {
    somenewoptions: {}
  });
}

@@ -25,7 +25,9 @@ class ErrorHandler{
wrapBarcodeCall(func){
try{
var result = func(...arguments);
this.api._options.valid(true);
if (typeof this.api._options.valid !== 'undefined') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this.api._options.valid !== undefined should be enough, I think.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, you can do it in old specs as I see (http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.1.3). But for a public library your way is better :)


// Convert an option to a specified type
function convertOption(data, type) {
if (type === 'string') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe check type before:

if (typeof data !== type) {
  // do conversions
}
return data;

Copy link
Owner Author

Choose a reason for hiding this comment

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

type is the type it should be converted TO, not the type it already is. Or I might have misunderstood this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For example convertOption(10, 'number') causes return parseInt(data, 10); anyway. I suggest check type of data before and avoid any unnecessary conversion. Or I missed something :)

@SanichKotikov
Copy link
Collaborator

And please, do not forget about options for CODE128 :)

@lindell
Copy link
Owner Author

lindell commented Jul 8, 2017

Of course I will not 😉 I just added EAN to test with and there is a lot of other options thats need to be added.

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.

2 participants